Skip to content

perf: write profile samples directly - #442

Draft
BridgeAR wants to merge 1 commit into
mainfrom
BridgeAR/2026-11-18-direct-profile-consumer
Draft

BridgeAR wants to merge 1 commit into
mainfrom
BridgeAR/2026-11-18-direct-profile-consumer

Conversation

@BridgeAR

Copy link
Copy Markdown
Member

What does this PR do?:

Add time.stopEncoded() and heap.profileEncoded(). Callers can encode the collected snapshot without building Sample and Label objects. The existing object-returning methods stay unchanged.

Motivation:

Changing the encoder in the tracer is too late to avoid those allocations. The profiler can write samples directly as it visits them.

In the 6,500-sample wall-profile benchmark, the writer retained about 0.6 MiB instead of 3.2 MiB and reduced median total time from 4.5–4.7 ms to 2.7–2.8 ms. Median synchronous work rose from 1.7 ms to 2.5–2.6 ms.

Additional Notes:

Do not merge until DataDog/pprof-format#126 ships the ProfileWriter methods used here. Update the codec dependency and lockfile to that release, then run npm ci and npm run compile. DataDog/dd-trace-js#11302 will still use the object encoder until it pins a compatible @datadog/pprof release.

How to test the change?:

Local verification used a codec tarball from the staged writer revision of DataDog/pprof-format#126. That revision is not yet pushed. The current PR head and published codec lack the writer methods this branch needs. With the paired codec installed, run npm run test:js to check the encoded wall and heap paths against the existing object paths, and node --expose-gc benchmark/direct-profile-writer.cjs to compare the serializers.

On Node 26.3.1, 158 tests passed on this branch versus 154 on main at 3905f38. Both runs skipped 63 tests and failed the same assertion: the allocation OOM fixture dumped a profile but exited without a fatal error.

Object serialization builds Sample and Label objects for callers that only need bytes. Writing samples directly avoids retaining that object graph without changing the existing object-returning methods.
@datadog-prod-us1-6

datadog-prod-us1-6 Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Pipelines

✨ Unblock PR with BitsAI

❌ Errors

Your PR has failed checks. Please review the issues below and take necessary action before merging.

🚦 18 Pipeline jobs failed

Build | asan (26) — 🔧 Needs a code fix, caused by this PR

View more details · View in GitHub Actions

Build | build / alpine-test-22 — 🔧 Needs a code fix, caused by this PR

View more details · View in GitHub Actions

Build | build / centos-test-20 — 🔧 Needs a code fix, caused by this PR

View more details · View in GitHub Actions

View all 18 failed jobs.

Useful? React with 👍 / 👎

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

This branch has not been deployed

No deployments
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