fix: reduce ACF overhead in storage and noop contexts#7465
Conversation
Replace manual enterWith/restore patterns with run() across all noop context wrappers (log writer, exporters, git utils). This halves AsyncContextFrame transitions on Node.js 22+: run() restores via AsyncContextFrame.set() (no extra frame), while enterWith/restore created a second frame that triggered the profiler's setContext() again. In DatadogStorage, feature-detect whether ALS.run() delegates to enterWith() (ACF behavior) and only fall back to the manual approach on older runtimes without AsyncContextFrame.
Overall package sizeSelf size: 4.58 MB Dependency sizes| name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 2.0.6 | 81.92 kB | 813.08 kB | | dc-polyfill | 0.1.10 | 26.73 kB | 26.73 kB |🤖 This report was automatically generated by heaviest-objects-in-the-universe |
This comment has been minimized.
This comment has been minimized.
BenchmarksBenchmark execution time: 2026-02-10 17:06:13 Comparing candidate commit b04c8bd in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 229 metrics, 31 unstable metrics. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #7465 +/- ##
==========================================
- Coverage 80.34% 80.31% -0.04%
==========================================
Files 731 731
Lines 31093 31133 +40
==========================================
+ Hits 24982 25004 +22
- Misses 6111 6129 +18
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
rochdev
left a comment
There was a problem hiding this comment.
LGTM! Added a few comments but mostly just as notes.
| } | ||
|
|
||
| const hasExecArg = (arg) => process.execArgv.includes(arg) || String(NODE_OPTIONS).includes(arg) | ||
| const canUseAsyncContextFrame = samplingContextsAvailable && isACFActive |
There was a problem hiding this comment.
Not a fan of exposing isACFActive as that should be a hidden implementation detail, but it seems better than the current alternative.
| als.run(1, () => {}) | ||
| als.disable() | ||
| return active | ||
| })() |
There was a problem hiding this comment.
Doing this right at file load time can have side-effects, but I think that's fine because if this file is loaded then the rest of the library is probably loaded as well at which point we'll end up getting those side-effects anyway.
* fix: reduce ACF overhead in storage and noop contexts Replace manual enterWith/restore patterns with run() across all noop context wrappers (log writer, exporters, git utils). This halves AsyncContextFrame transitions on Node.js 22+: run() restores via AsyncContextFrame.set() (no extra frame), while enterWith/restore created a second frame that triggered the profiler's setContext() again. In DatadogStorage, feature-detect whether ALS.run() delegates to enterWith() (ACF behavior) and only fall back to the manual approach on older runtimes without AsyncContextFrame. * doc: remove todo by explaining the behavior * fix: exclude node:internals ALS from path line detection (#7475)
* fix: reduce ACF overhead in storage and noop contexts Replace manual enterWith/restore patterns with run() across all noop context wrappers (log writer, exporters, git utils). This halves AsyncContextFrame transitions on Node.js 22+: run() restores via AsyncContextFrame.set() (no extra frame), while enterWith/restore created a second frame that triggered the profiler's setContext() again. In DatadogStorage, feature-detect whether ALS.run() delegates to enterWith() (ACF behavior) and only fall back to the manual approach on older runtimes without AsyncContextFrame. * doc: remove todo by explaining the behavior * fix: exclude node:internals ALS from path line detection (#7475)
Replace manual enterWith/restore patterns with run() across all noop context wrappers (log writer, exporters, git utils). This halves AsyncContextFrame transitions on Node.js 22+: run() restores via AsyncContextFrame.set() (no extra frame), while enterWith/restore created a second frame that triggered the profiler's setContext() again.
In DatadogStorage, feature-detect whether ALS.run() delegates to enterWith() (ACF behavior) and only fall back to the manual approach on older runtimes without AsyncContextFrame.