benchmark: add micro-benchmarks for TraceID hex formatting and parsing#311
Conversation
xlamorlette-datadog
left a comment
There was a problem hiding this comment.
Please, what is you personal objective in submitting this PR?
168c7b0 to
455299d
Compare
|
Hi @xlamorlette-datadog, thanks for the review and the great catch on the padding paths! To answer your question, I'm currently an undergraduate studying computer science with an interest in low-latency systems and performance-oriented C++. My goal with this PR is to add measurable coverage for these serialization paths so that future allocation-reduction work (e.g., using std::to_chars with stack-allocated buffers to avoid the std::string heap allocation) can be evaluated with concrete latency data instead of guesswork. I completely agree with testing the edge cases, and I've just pushed a commit that factorizes the tests using BENCHMARK_CAPTURE exactly as you suggested. One interesting finding from my local runs is that BM_TraceID_HexPadded/WithPadding ({1, 0}) actually ran faster than the NoPadding case (~88 ns vs ~131 ns on my machine). It looks like when high == 0 the implementation skips formatting the high half entirely, which is why the WithPadding case ends up faster despite the name. Let me know if the new structure looks good, thanks again for the review. |
|
|
Some CI jobs are failing because this comes from a fork. I'm going to mirror this PR in our main repository. |
|
All CI jobs are green on the mirrored (draft) PR. |
|
@AneesPatel Would you please be able to sign your commits? |
455299d to
3e8fece
Compare
|
@AneesPatel Thanks for your contribution! |
Description
Adds
benchmark/trace_id_bench.cppto introduce targeted Google Benchmark coverage for the 128-bit and 64-bit TraceID formatting paths. Also updatesbenchmark/CMakeLists.txtto include the new benchmark executable.Baseline Metrics (Ubuntu 22.04 / GCC 11.4):
BM_TraceID_HexPaddedstd::stringallocations and concatenation.BM_TraceID_ParseHex_128bittraceparentextraction path.BM_TraceID_ParseHex_64bitBM_HexPadded_uint64to_chars+std::stringalloc.BM_Hex_uint64Motivation
TraceID::hex_padded()is called on every outgoing W3Ctraceparentheader injection, andTraceID::parse_hex()on every incoming extraction. Because these functions sit in the hottest path of distributed tracing, their latency and allocation overhead multiply across millions of spans.Currently, the underlying
hex_padded<uint64_t>()andhex<uint64_t>()functions utilize a stack-buffer-to-std::stringpattern. While the existingBM_TraceTinyCCSourcebenchmark provides excellent end-to-end throughput data, it cannot isolate micro-regressions in these specific serialization operations.This baseline provides the data needed to safely prevent future regressions and evaluate allocation-reduction strategies in the critical path.
Jira ticket
N/A
Additional Notes
How to run