Skip to content

benchmark: add micro-benchmarks for TraceID hex formatting and parsing#311

Open
AneesPatel wants to merge 2 commits intoDataDog:mainfrom
AneesPatel:bench/trace-id-hex-utilities
Open

benchmark: add micro-benchmarks for TraceID hex formatting and parsing#311
AneesPatel wants to merge 2 commits intoDataDog:mainfrom
AneesPatel:bench/trace-id-hex-utilities

Conversation

@AneesPatel
Copy link
Copy Markdown

Description

Adds benchmark/trace_id_bench.cpp to introduce targeted Google Benchmark coverage for the 128-bit and 64-bit TraceID formatting paths. Also updates benchmark/CMakeLists.txt to include the new benchmark executable.

Baseline Metrics (Ubuntu 22.04 / GCC 11.4):

Benchmark Time (ns/op) Iterations Notes
BM_TraceID_HexPadded 204 ns 3.6M Full 128-bit ID to 32-char hex. Cost reflects two underlying std::string allocations and concatenation.
BM_TraceID_ParseHex_128bit 108 ns 6.5M W3C traceparent extraction path.
BM_TraceID_ParseHex_64bit 60 ns 11.8M Legacy 64-bit extraction path.
BM_HexPadded_uint64 46 ns 17.6M Single to_chars + std::string alloc.
BM_Hex_uint64 24 ns 29.5M No padding.

Motivation

TraceID::hex_padded() is called on every outgoing W3C traceparent header injection, and TraceID::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>() and hex<uint64_t>() functions utilize a stack-buffer-to-std::string pattern. While the existing BM_TraceTinyCCSource benchmark 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

  • Validated locally via Linux (WSL2 Ubuntu 22.04) with GCC 11.4.

How to run

mkdir .build && cd .build
cmake .. -DDD_TRACE_BUILD_BENCHMARK=1 -DCMAKE_BUILD_TYPE=Release
make -j
./benchmark/dd_trace_cpp-benchmark --benchmark_filter='^BM_TraceID|^BM_Hex'

@AneesPatel AneesPatel requested review from a team as code owners April 23, 2026 03:31
@AneesPatel AneesPatel requested review from tabgok and removed request for a team April 23, 2026 03:31
@tabgok tabgok requested review from xlamorlette-datadog and removed request for tabgok April 30, 2026 18:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant