Skip to content

Add an async stack sampler addon to the Node 26 native packages - #40

Draft
jrsells wants to merge 1 commit into
jrsells/node-v26.13.1-pprof-pointer-compressionfrom
jrsells/node-v26.13.1-async-stack-sampler
Draft

jrsells wants to merge 1 commit into
jrsells/node-v26.13.1-pprof-pointer-compressionfrom
jrsells/node-v26.13.1-async-stack-sampler

Conversation

@jrsells

@jrsells jrsells commented Dec 1, 2026 •

Copy link
Copy Markdown

Summary

Agent notes (Claude Opus 5.5)

V8's CPU profiler drops the await chain, so LunaServer's Datadog profiles can't show which of our code a hot function was running for. This adds @asana/async-stack-sampler, a small native addon built into the Node packages tarball next to pprof. A timer thread requests an interrupt. On the main thread, the interrupt captures the stack through the public Exception::CaptureStackTrace API, await chain included, plus the async context, so the caller can match each sample to its request. Stacked on #39 for the Dockerfile changes. LunaServer side: codez#473225.

Tradeoffs

  • It uses only the public V8 API, so it doesn't depend on V8's internal layouts the way the pprof patch does. It loses the leaf frame when the interrupt lands in native code, and each sample allocates about 2 KB until it's formatted.
  • It runs on the main thread only and samples only between start() and stop(), which LunaServer calls per diagnosed request.

Asana tasks: https://app.asana.com/1/15793206719/dev/space/1220418525288093/ticket/1220638641742555

CC:

Test Plan

  • Built with node-gyp against stock Node 26.13.1 on a Mac (arm64), and the smoke test passes. CPU burned 1:3 under two callers shows both callers in the sampled await chains (66 and 191 samples), and every sample's async context matches its caller. With --stress-compaction it took 269 samples, with 2.9 ms of capture time in total.
  • Earlier prototype of the same capture approach: 25–49µs per sample, about 0.5% of a core at 100 Hz.
  • Not yet done: building this Dockerfile (no Docker here) on x64 and arm64, and testing on pointer-compressed nodejs26pc.

CPU profilers record only the synchronous stack, so in LunaServer most
samples root at processTicksAndRejections with no caller. This addon
samples the stack with V8's await chain from an interrupt, keeps V8's raw
frames and the async context, and leaves formatting for after the request.
It uses only the public V8 API, and builds against our headers like pprof.

Co-authored-by: Cursor <cursoragent@cursor.com>
@command-by-asana

Copy link
Copy Markdown

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant