← Back to Pull requests

perf(otlp-transformer): decode hex IDs with a lookup table #7386

Open
unknown opened this pull request with 356 lines diff across 4 files
View on GitHub
unknown unknown commented on Nov 24, 2026 17:19 UTC
Author

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 with intValue(), 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

writeHexToBinary now looks each character up in a 128-entry Uint8Array table instead of calling intValue(). The character code is masked with & 0x7f so 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 on main and on this branch.

Benchmarks

Node.js v26.13.1, Linux, pinned to one core with taskset, baseline main at c15964b82. The benchmark serializes 3,000 batches of 512 spans with ProtobufTraceSerializer.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 from perf 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:bench results: their run-to-run variation on this machine is larger than this change.

Type of change

  • Performance improvement (non-breaking, no behaviour change for valid input)
  • How Has This Been Tested?

  • @opentelemetry/otlp-transformer unit tests (251 passing), including a new hexToBinary test

  • eslint and tsc
  • Checklist:

  • Followed the style guidelines of this project

  • Unit tests have been added

  • Documentation has been updated (not applicable)
  • Diff: 356 lines (+267 / -89) across 4 files Reviewer: legendecas Review duration: 3415m
    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
    0.43
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 42.5% (MEDIUM) · Higher = larger blast radius
    42.5%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 22.7% · Safe to merge
    22.7%