-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 trace_context performance #4721
Conversation
* using strings.Builder instead of fmt.Sprint * using strings.Cut instead of strings.Split * using hex.Decode instead of hex.DecodeString * avoid use regexp
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #4721 +/- ##
=======================================
+ Coverage 81.8% 81.9% +0.1%
=======================================
Files 224 224
Lines 18113 18116 +3
=======================================
+ Hits 14817 14847 +30
+ Misses 3000 2982 -18
+ Partials 296 287 -9
|
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.
LGTM👍
|
@MrAlias please check again, thanks |
It seems like I was confusing old vs new in my last comment. The benchstat output was helpful in clarifying this. |
@MrAlias all suggestion modified, please check again, thanks |
newest code benchmark result
|
@MrAlias all comment fixed, please check again, thanks |
Propagation is essential logic, regardless of whether it hits sampling. In the past, the implementation of Propagation did not prioritize memory management, allocating a lot of temporary heap memory. This caused 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 Propagation:
Typical client span Propagation
It can be seen that the poor performance of Propagation is mainly due to regular expressions and Sprintf.
This CR can significantly improve Propagation by optimizing it in the following ways:
Use string.Builder to pre-allocate memory
Use hex.Decode to a stack-based [N]byte array instead of hex.DecodeString, which temporarily allocates a heap-based string.
Use strings.Cut instead of strings.Split
Avoid using regex
All unit tests pass. Benchmarks:
New logic:
Old logic:
It can be seen that the performance has improved by about 2-3 times.