perf(otlp-transformer): decode hex IDs with a lookup table #7386
All Vouch review confidence checks passed
Residual risk 0.23 = Change Risk (0.43) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.43 · 356 lines diff across 4 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.352
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #7386"
general
weight: 0.35
legendecas
Which problem is this PR solving?
Refs #6100
Every exported span writes its trace ID, span ID and (for child spans) parent span ID through
writeHexToBinary, which decodes each hex character withintValue(), up to three range checks per character. That's 48 characters per span, or 64 with a parent span ID, and which range check matches depends on the random ID, so the branches are hard to predict.Short description of the changes
writeHexToBinarynow looks each character up in a 128-entryUint8Arraytable instead of callingintValue(). The character code is masked with& 0x7fso the index always stays in range.Valid hex, lowercase or uppercase, decodes exactly as before. Characters that aren't hex digits now decode to 0, where
intValue()returned an arbitrary value (charCode - 55). Trace and span IDs are validated as hex when spans are created, so this doesn't change what valid telemetry serializes to.I added a test that decodes every byte value from its lowercase and uppercase hex form and compares it with
parseInt. It passes onmainand on this branch.Benchmarks
Node.js v26.13.1, Linux, pinned to one core with
taskset, baselinemainat c15964b82. The benchmark serializes 3,000 batches of 512 spans withProtobufTraceSerializer.serializeRequest: half HTTP server spans with 13 attributes and half HTTP client spans with 8, on a resource with 19 attributes. Before and after builds alternated over three rounds; the table shows medians. Instruction and cycle counts come fromperf stat(3 repeats per build); instructions per span have Node.js startup subtracted.| Measurement | CommonJS before → after | ESM before → after |
|---|---|---|
| Instructions per span | 36.7k → 35.7k (−2.7%) | 38.0k → 36.8k (−3.1%) |
| Cycles, whole run | 20.76B → 19.57B (−5.7%) | 21.64B → 20.24B (−6.5%) |
| Time per span | 4,401 ns → 4,106 ns (−6.7%) | 4,571 ns → 4,300 ns (−5.9%) |
The before and after ranges were separated in every row. The change saves more cycles than instructions, as expected from removing hard-to-predict branches.
On top of #7385, which makes string writes cheaper so IDs are a larger share of what's left, the same change measured −8.8% cycles and −6.7% time per span (CommonJS) and −6.3% cycles and −7.0% time per span (ESM).
I haven't included the package's
test:benchresults: their run-to-run variation on this machine is larger than this change.Type of change
How Has This Been Tested?
@opentelemetry/otlp-transformerunit tests (251 passing), including a newhexToBinarytesteslintandtscChecklist: