-
Notifications
You must be signed in to change notification settings - Fork 2
Proposal: Expose bytes from TraceID #18
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
Conversation
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.
Thanks @t089 for the performance improvement and for providing benchmarks as well 🙏 The changes look solid to me, with a couple of nitpicks regarding public API, documentation, and formatting inline.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #18 +/- ##
=======================================
Coverage 99.50% 99.50%
=======================================
Files 6 6
Lines 402 402
=======================================
Hits 400 400
Misses 2 2 ☔ View full report in Codecov by Sentry. |
Hm thinking about it again, I wonder if the nested type Wouldn't it be enough to just remove the current |
@slashmo updated the API. Main idea is, if you use "bytes" to create an id you should be able to get the bytes out again. "Bytes" are a fixed size collection of bytes, which internally map to a tuple. |
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.
Great job! 👏 Do we still need to expose the unsafe APIs publicly now that we can subscript into the Span/TraceID.Bytes
directly? I prefer to start with as little public API as possible where it makes sense.
I would suggest to expose the "fixed-width 16 byte array" directly on
TraceID
andSpanID
for performance reasons. Otherwise, clients will too easily go through thevar bytes: [UInt8]
property which causes an allocation on every access. Of course this is a breaking change of the API, but the performance win seems worthwhile.For example, while implementing a
TraceIdRatioBasedSampler
here I had to access the last 8 bytes of theTraceID
to determine if the sample should be dropped or recorded. When going through thevar bytes: [UInt8]
this causes an allocation on each check. If I use the approach presented here, there are 0 allocations.I also changed the conformance to
Identifiable
to use the type itself as the "id".With
Benchmark
I was able to measure the difference:Benchmark
With
[UInt8]
With
unsafeBytes
The throughput roughly doubles, which I would consider a great win for a tracing library which usually is executed in hot code paths.