Skip to content

perf(trace-encoder): cache stable strings across payloads - #10057

Open
BridgeAR wants to merge 4 commits into
masterfrom
BridgeAR/2026-08-28-trace-string-cache
Open

perf(trace-encoder): cache stable strings across payloads#10057
BridgeAR wants to merge 4 commits into
masterfrom
BridgeAR/2026-08-28-trace-string-cache

Conversation

@BridgeAR

@BridgeAR BridgeAR commented Aug 28, 2026

Copy link
Copy Markdown
Member

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.

@dd-octo-sts

dd-octo-sts Bot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Overall package size

Self size: 8.64 MB
Deduped: 9.31 MB
No deduping: 9.31 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

@datadog-datadog-us1-prod

datadog-datadog-us1-prod Bot commented Aug 28, 2026

Copy link
Copy Markdown

Tests

All CI checks and tests passed.

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 98.63% (+0.00%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 2e15397 | Docs | View more details | Give us feedback!

@pr-commenter

pr-commenter Bot commented Aug 28, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-08-31 21:43:18

Comparing candidate commit 2e15397 in PR branch BridgeAR/2026-08-28-trace-string-cache with baseline commit bf29c82 in branch master.

📊 Benchmarking dashboard

Found 0 performance improvements and 0 performance regressions! Performance is the same for 2300 metrics, 10 unstable metrics.

Explanation

This is an A/B test comparing a candidate commit's performance against that of a baseline commit. Performance changes are noted in the tables below as:

  • 🟩 = significantly better candidate vs. baseline
  • 🟥 = significantly worse candidate vs. baseline

We compute a confidence interval (CI) over the relative difference of means between metrics from the candidate and baseline commits, considering the baseline as the reference.

If the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD), the change is considered significant.

Feel free to reach out to #apm-benchmarking-platform on Slack if you have any questions.

More details about the CI and significant changes

You can imagine this CI as a range of values that is likely to contain the true difference of means between the candidate and baseline commits.

CIs of the difference of means are often centered around 0%, because often changes are not that big:

---------------------------------(------|---^--------)-------------------------------->
                              -0.6%    0%  0.3%     +1.2%
                                 |          |        |
         lower bound of the CI --'          |        |
sample mean (center of the CI) -------------'        |
         upper bound of the CI ----------------------'

As described above, a change is considered significant if the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD).

For instance, for an execution time metric, this confidence interval indicates a significantly worse performance:

----------------------------------------|---------|---(---------^---------)---------->
                                       0%        1%  1.3%      2.2%      3.1%
                                                  |   |         |         |
       significant impact threshold --------------'   |         |         |
                      lower bound of CI --------------'         |         |
       sample mean (center of the CI) --------------------------'         |
                      upper bound of CI ----------------------------------'

Unstable benchmarks

These benchmarks have a confidence interval too wide to call a change; treat them as noise rather than signal.

scenario:appsec-appsec-enabled-20

  • unstable max_rss_usage [-19.995MB; +32.233MB] or [-11.351%; +18.299%]

scenario:appsec-appsec-enabled-with-attacks-20

  • unstable max_rss_usage [-13.876MB; +3.970MB] or [-7.946%; +2.274%]

scenario:debugger-line-probe-with-snapshot-minimal-24

  • unstable max_rss_usage [-15.163MB; +12.672MB] or [-6.271%; +5.241%]

scenario:dogstatsd-with-tags-20

  • unstable cpu_user_time [-391.918ms; +144.661ms] or [-8.246%; +3.044%]
  • unstable execution_time [-383.437ms; +147.108ms] or [-7.927%; +3.041%]
  • unstable throughput [-50941.291op/s; +128738.406op/s] or [-2.942%; +7.434%]

scenario:llmobs-encode-unicode-mixed-20

  • unstable max_rss_usage [-8.719MB; +5.303MB] or [-10.762%; +6.546%]

scenario:plugin-claude-agent-sdk-compact-stream-scan-24

  • unstable cpu_usage_percentage [-7.007%; +3.312%]

scenario:plugin-claude-agent-sdk-compact-stream-scan-26

  • unstable cpu_usage_percentage [-5.073%; +5.180%]

scenario:test-optimization-large-suite-20

  • unstable max_rss_usage [-8.097MB; +1.575MB] or [-9.829%; +1.912%]

@codecov

codecov Bot commented Aug 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.62%. Comparing base (bf29c82) to head (2e15397).

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            
Flag Coverage Δ
aiguard 63.30% <97.00%> (+0.14%) ⬆️
aiguard-integration 59.06% <75.50%> (+0.06%) ⬆️
apm-bucket-0 62.68% <97.00%> (+0.16%) ⬆️
apm-bucket-1 68.08% <97.00%> (+0.12%) ⬆️
apm-bucket-2 67.65% <97.00%> (+0.13%) ⬆️
apm-bucket-3 64.52% <97.00%> (+0.15%) ⬆️
apm-capabilities-tracing 62.62% <100.00%> (+0.06%) ⬆️
apm-integrations-aerospike 60.71% <97.00%> (+0.18%) ⬆️
apm-integrations-confluentinc-kafka-javascript 66.74% <97.00%> (+0.09%) ⬆️
apm-integrations-couchbase 61.21% <97.00%> (+0.17%) ⬆️
apm-integrations-http 66.34% <97.00%> (+0.11%) ⬆️
apm-integrations-kafkajs 67.35% <97.00%> (+0.12%) ⬆️
apm-integrations-next 64.01% <97.00%> (+0.15%) ⬆️
apm-integrations-prisma 62.04% <97.00%> (+0.14%) ⬆️
appsec 76.80% <97.00%> (+0.06%) ⬆️
appsec-express_fastify_graphql 72.77% <98.00%> (+0.07%) ⬆️
appsec-integration 49.58% <82.50%> (+0.06%) ⬆️
appsec-kafka_ldapjs_lodash 67.56% <97.00%> (+0.10%) ⬆️
appsec-mongodb-core_mongoose_mysql 70.72% <97.00%> (+0.07%) ⬆️
appsec-next 57.26% <97.00%> (+0.12%) ⬆️
appsec-node-serialize_passport_postgres 70.19% <97.00%> (+0.08%) ⬆️
appsec-sourcing_stripe_template 68.63% <97.00%> (+0.09%) ⬆️
debugger 69.07% <93.10%> (-0.04%) ⬇️
instrumentations-bucket-0 56.08% <75.86%> (-0.02%) ⬇️
instrumentations-bucket-1 64.33% <97.00%> (+0.15%) ⬆️
instrumentations-bucket-10 53.30% <75.86%> (-0.01%) ⬇️
instrumentations-bucket-11 65.76% <97.00%> (+0.13%) ⬆️
instrumentations-bucket-12 61.58% <97.00%> (+0.17%) ⬆️
instrumentations-bucket-13 56.31% <66.00%> (+0.02%) ⬆️
instrumentations-bucket-14 55.77% <66.00%> (+0.02%) ⬆️
instrumentations-bucket-2 56.96% <66.00%> (+0.02%) ⬆️
instrumentations-bucket-3 57.17% <66.00%> (+0.02%) ⬆️
instrumentations-bucket-4 63.95% <97.00%> (+0.15%) ⬆️
instrumentations-bucket-5 56.53% <75.86%> (-0.02%) ⬇️
instrumentations-bucket-6 58.28% <97.00%> (+0.14%) ⬆️
instrumentations-bucket-7 65.82% <97.00%> (+0.15%) ⬆️
instrumentations-bucket-8 63.09% <97.00%> (+0.16%) ⬆️
instrumentations-bucket-9 64.67% <97.00%> (+0.14%) ⬆️
instrumentations-instrumentation-couchbase 54.69% <75.86%> (-0.02%) ⬇️
instrumentations-instrumentation-zlib 55.80% <66.00%> (+0.03%) ⬆️
instrumentations-integration-esbuild 34.50% <ø> (ø)
llmobs-ai_anthropic_bedrock 66.81% <97.00%> (+0.11%) ⬆️
llmobs-bucket-1 64.97% <97.00%> (+0.11%) ⬆️
llmobs-openai 66.83% <97.00%> (+0.12%) ⬆️
llmobs-openai-agents_vertex-ai 64.11% <97.00%> (+0.11%) ⬆️
llmobs-sdk 76.02% <97.00%> (+0.09%) ⬆️
master-coverage 98.62% <100.00%> (?)
openfeature 59.67% <79.00%> (+0.08%) ⬆️
openfeature-unit 58.27% <75.86%> (-0.02%) ⬇️
platform-core_esbuild_instrumentations-misc 41.08% <75.86%> (-0.01%) ⬇️
platform-integration 64.84% <76.50%> (+0.04%) ⬆️
platform-shimmer_unit-guardrails_webpack 38.91% <75.86%> (-0.01%) ⬇️
plugins-browser-bunyan_bullmq_cassandra 66.37% <97.00%> (+0.12%) ⬆️
plugins-bucket-0 61.09% <97.00%> (+0.15%) ⬆️
plugins-bucket-1 58.22% <76.50%> (+0.08%) ⬆️
plugins-bucket-11 67.81% <97.00%> (+0.11%) ⬆️
plugins-bucket-18 65.56% <97.00%> (+0.11%) ⬆️
plugins-bucket-19 65.10% <97.00%> (+0.16%) ⬆️
plugins-bucket-20 68.78% <98.00%> (+0.12%) ⬆️
plugins-bucket-4 61.25% <97.00%> (+0.16%) ⬆️
plugins-cookie_cookie-parser_crypto 55.67% <75.86%> (-0.02%) ⬇️
plugins-fastify_fetch_fs 65.48% <97.00%> (+0.14%) ⬆️
plugins-generic-pool_google-cloud-pubsub_grpc 69.05% <97.00%> (+0.10%) ⬆️
plugins-handlebars_hapi_hono 63.76% <97.00%> (+0.15%) ⬆️
plugins-ioredis_knex_langgraph 61.78% <97.00%> (+0.16%) ⬆️
plugins-ldapjs_light-my-request_limitd-client 63.47% <97.00%> (+0.14%) ⬆️
plugins-lodash_mariadb_memcached 63.95% <97.00%> (+0.15%) ⬆️
plugins-moleculer_mongodb_mongodb-core 66.20% <97.00%> (+0.14%) ⬆️
plugins-mongoose_multer_mysql 64.06% <97.00%> (+0.15%) ⬆️
plugins-mysql2_nats_node-serialize 66.27% <97.00%> (+0.14%) ⬆️
plugins-opensearch_passport-http_pino 64.17% <97.00%> (+0.15%) ⬆️
plugins-postgres_process_pug 63.22% <97.00%> (+0.16%) ⬆️
plugins-redis_router_sequelize 66.76% <97.00%> (+0.14%) ⬆️
plugins-test-and-upstream-rhea_undici_url 66.10% <98.00%> (+0.12%) ⬆️
plugins-valkey_vm_winston 62.55% <97.00%> (+0.21%) ⬆️
plugins-ws 64.60% <97.00%> (+0.15%) ⬆️
profiling 66.19% <93.10%> (-0.02%) ⬇️
serverless-aws-sdk-aws-sdk 55.58% <97.00%> (+0.15%) ⬆️
serverless-aws-sdk-base-inject-field 55.25% <75.86%> (-0.02%) ⬇️
serverless-aws-sdk-bedrockruntime 58.44% <97.00%> (+0.16%) ⬆️
serverless-aws-sdk-client 60.20% <97.00%> (+0.14%) ⬆️
serverless-aws-sdk-dynamodb 59.30% <97.00%> (+0.15%) ⬆️
serverless-aws-sdk-eventbridge 57.76% <97.00%> (+0.13%) ⬆️
serverless-aws-sdk-kinesis 63.24% <97.00%> (+0.12%) ⬆️
serverless-aws-sdk-lambda 61.23% <97.00%> (+0.15%) ⬆️
serverless-aws-sdk-s3 59.35% <97.00%> (+0.16%) ⬆️
serverless-aws-sdk-serverless-peer-service 63.81% <97.00%> (+0.12%) ⬆️
serverless-aws-sdk-sns 64.12% <97.00%> (+0.12%) ⬆️
serverless-aws-sdk-sqs 64.61% <97.00%> (+0.15%) ⬆️
serverless-aws-sdk-stepfunctions 59.21% <97.00%> (+0.16%) ⬆️
serverless-aws-sdk-util 55.86% <75.86%> (-0.02%) ⬇️
serverless-bucket-0 57.76% <68.96%> (-0.01%) ⬇️
serverless-bucket-1 63.82% <97.00%> (+0.13%) ⬆️
test-optimization-cucumber 70.50% <66.66%> (-0.01%) ⬇️
test-optimization-cypress 64.71% <66.66%> (+0.04%) ⬆️
test-optimization-jest 72.05% <68.96%> (-0.01%) ⬇️
test-optimization-mocha 71.94% <68.96%> (+0.03%) ⬆️
test-optimization-playwright-playwright-atr 59.77% <22.22%> (-0.07%) ⬇️
test-optimization-playwright-playwright-efd 60.40% <0.00%> (-0.06%) ⬇️
test-optimization-playwright-playwright-final-status 60.02% <0.00%> (-0.06%) ⬇️
test-optimization-playwright-playwright-impacted-tests 60.13% <0.00%> (+0.08%) ⬆️
test-optimization-playwright-playwright-reporting 61.09% <66.66%> (-0.07%) ⬇️
test-optimization-playwright-playwright-test-management 61.18% <0.00%> (-0.06%) ⬇️
test-optimization-playwright-playwright-test-span 59.81% <22.22%> (-0.02%) ⬇️
test-optimization-selenium 58.84% <22.22%> (-0.10%) ⬇️
test-optimization-testopt 61.82% <76.00%> (+0.09%) ⬆️
test-optimization-vitest 72.65% <66.66%> (+0.05%) ⬆️
test-optimization-vitest-browser 58.68% <0.00%> (-0.06%) ⬇️
test-optimization-webdriverio 65.48% <75.86%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.
@BridgeAR
BridgeAR force-pushed the BridgeAR/2026-08-28-trace-string-cache branch from 2598d01 to 2e15397 Compare August 31, 2026 21:33
@BridgeAR
BridgeAR marked this pull request as ready for review August 31, 2026 21:41
@BridgeAR
BridgeAR requested review from a team as code owners August 31, 2026 21:41

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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 {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant