perf(trace-encoder): cache stable strings across payloads - #10057
perf(trace-encoder): cache stable strings across payloads#10057BridgeAR wants to merge 4 commits into
Conversation
Overall package sizeSelf size: 8.64 MB Dependency sizes| name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 3.4.0 | 127.33 kB | 447.04 kB | | opentracing | 0.14.7 | 194.81 kB | 194.81 kB | | dc-polyfill | 0.1.11 | 25.74 kB | 25.74 kB |🤖 This report was automatically generated by heaviest-objects-in-the-universe |
|
✅ All CI checks and tests passed. 🎉 All green!🧪 All tests passed 🎯 Code Coverage (details) 🔗 Commit SHA: 2e15397 | Docs | View more details | Give us feedback! |
BenchmarksBenchmark execution time: 2026-08-31 21:43:18 Comparing candidate commit 2e15397 in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 2300 metrics, 10 unstable metrics.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #10057 +/- ##
========================================
Coverage 98.62% 98.62%
========================================
Files 996 997 +1
Lines 152043 152230 +187
Branches 13084 12804 -280
========================================
+ Hits 149956 150143 +187
Misses 2087 2087
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Short strings repeat across trace payloads, but the encoder rewrites their UTF-8 bytes for every payload. Both candidate and retained generations remain bounded. Repeated isolated runs made encode-and-flush 28.2% to 41.0% faster. Sampled Lambda allocations decreased by 3.43%.
Immediate Lambda flushes otherwise re-encode stable span identities and tag keys for every payload. The cache learns bounded consecutive repeats and disables after two low-reuse payloads, which keeps arbitrary values and buffered encoders on the original path. On Node 22.23.2, stable 96-tag payloads improve from 33,512 to 24,557 ns/op. Fully unique payloads improve from 37,126 to 33,809 ns/op. Five-trial Lambda allocation profiles fall by 1.75% to 8.24% across the six application shapes.
Cross-payload reuse applies only to immediate 0.4 payloads. Buffered and 0.5 writers use the regular encoder, and low-reuse immediate workloads switch back after bounded learning. On Node 22.23.1 (V8 12.4.254.21-node.56), three isolated-process pairs used a 1 s warm-up and seven 250 ms trials each. Small payloads decreased from 654.4 to 443.1 ns/trace. Payloads with 96 tags decreased from 20,302 to 15,474 ns/trace.
Retained strings bypassed the per-payload cache, so each matching span repeated the cross-payload lookup.
2598d01 to
2e15397
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2e15397c9c
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| const CROSS_PAYLOAD_STRING_LIMIT = 256 | ||
| const crossPayloadStates = new WeakMap() | ||
|
|
||
| class CrossPayloadAgentEncoder extends AgentEncoder { |
There was a problem hiding this comment.
Add a reproducible cross-payload benchmark
This introduces a WeakMap-backed subclass and adaptive state machine on the trace-encoding hot path, but no benchmark was added or updated to reproduce the reported gains. The existing benchmark/sirun/encoding/index.js imports the regular 0.4 AgentEncoder and never calls makePayload() in its measured loop, so it cannot exercise this cross-payload cache or guard against regressions in its learning and fallback paths; add a focused benchmark that instantiates this encoder and flushes between traces.
AGENTS.md reference: AGENTS.md:L116-L117
Useful? React with 👍 / 👎.
Reuse encoded span identity strings and tag keys across immediate 0.4 trace payloads. The cache retains at most 256 strings, tracks at most 512 candidates, and rejects retained entries above 256 encoded bytes. Low-reuse workloads switch back to the regular encoder, while buffered and 0.5 writers use that encoder throughout.
On Node 22.23.1 (V8 12.4.254.21-node.56), three alternating isolated-process pairs used a 1 s warm-up and seven 250 ms trials per process. Small payloads decreased from 654.4 to 443.1 ns/trace. Payloads with 96 tags decreased from 20,302 to 15,474 ns/trace.