-
Notifications
You must be signed in to change notification settings - Fork 126
Precompute hex encodings of SpanID and TraceID #874
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
Thanks! Though I feel like there is a reason we didn't use this already... I think OTP version support. Ah yea, |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #874 +/- ##
==========================================
- Coverage 17.53% 16.90% -0.64%
==========================================
Files 24 24
Lines 713 710 -3
==========================================
- Hits 125 120 -5
- Misses 588 590 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
I'd be curious if this also saves you any time: #590 |
Agree on precomputing. It'd also be nice if attach didn't always add those encodings to the log context but now that it does I'm not sure we can remove it without a major version bump... :( |
I tried a more involved version with:
...and got ~250k ips. Much better than
Yes! that's something I've been thinking of, but even slightly farther - make the hex-encoded representation the canonical one :D I applied your patch over the release version; it benchmarks slightly faster than just
The way I did it adds two fields to |
Yes, I think we can add to span_ctx without a major version bump. Maybe theoretically we can't but I don't think its stopped us before :), and those should only be used through functions on a local node, not passed between nodes or accessed with |
binary:encode_hex/2
instead of io_lib:format/2
Added precomputing code. Here's a quick benchmark between >=OTP26, >=OTP24, <OTP24 encoding routines. This is still for the whole
|
This is still really needed for logs. It's a nightmare dealing with it encoded. |
Can we merge this as-is while better (and more involved) future approaches are considered? |
Thanks for the run, will get the |
Done. There's an ordering problem with
|
@kzemek sorry about dropping the ball on this. Can you rebase so we can merge? |
`io_lib:format/2` has very significant overhead over `binary:encode_hex/2`.
@tsloughter Rebased |
Squashed commit of the following: commit 7fb96fb Author: Konrad Zemek <[email protected]> Date: Thu Jul 31 19:51:04 2025 +0200 Prefill hex IDs in remaining span_ctx constructors commit ca05789 Author: Konrad Zemek <[email protected]> Date: Fri Jul 25 12:05:50 2025 +0200 Precompute hex trace and span ids commit 0564be2 Author: Konrad Zemek <[email protected]> Date: Wed Jul 23 11:36:23 2025 +0200 Use `binary:encode_hex/2` instead of `io_lib:format/2` `io_lib:format/2` has very significant overhead over `binary:encode_hex/2`.
io_lib:format/2
has very significant overhead overbinary:encode_hex/2
. This has shown up prominently in our profiling of small spanned functions (think a happy-pathCache.get()
).Benchmark results
Benchee code
Flamegraph overview