New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
improve tracestate performance #4722
Conversation
* use string.Builder to directly construct the result * reduce the redundant copying during Insert * avoid using regex
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #4722 +/- ##
=====================================
Coverage 81.9% 81.9%
=====================================
Files 224 224
Lines 18136 18208 +72
=====================================
+ Hits 14865 14930 +65
- Misses 2984 2989 +5
- Partials 287 289 +2
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use benchstat to make comparisons between benchmarks in your description.
The increases in allocations is concerning. The impact on GC is not captured in the benchmarks but will be when it is run on real systems. |
|
original benchmark result |
Please address the latest CI failures. Also, please provided updated benchmark results for the applied changes. |
sorry forgot upload benchmark result. here it is
all case are better except only |
@MrAlias all comment fixed, please check again, thanks |
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
@MrAlias Yes,Committed the code |
@MrAlias Here it is
|
i didn't put result before, because i think it is obviously better |
Tracestate is essential logic that cannot be skipped in some scenarios that use tracestate. In the past, the implementation of tracestate did not prioritize performance, using complex regular expressions, causing its efficiency to be low. In some scenarios, too much CPU was wasted.
For example, even if it doesn't hit sampling, startServerSpan consumes 25% of the entire request CPU.
Typical server span tracestate:
Typical client span Propagation
It can be seen that the poor performance of tracestate is mainly due to regular expressions and member.String.
This CR can significantly improve Propagation by optimizing it in the following ways:
Use string.Builder to directly construct the result
Reduce the redundant copying during Insert
Avoid using regex
All unit tests pass. Benchmarks:
It can be seen that the performance has improved by about 2-3 times.