src: skip the async id stack when nobody sees it - #66511
Draft
nigrosimone wants to merge 1 commit into
Draft
nigrosimone wants to merge 1 commit into
nigrosimone wants to merge 1 commit into
Conversation
With no async hook and no executionAsyncResource() user, every InternalCallbackScope pushed and popped the async ids on the stack, only for executionAsyncId() and triggerAsyncId() to read the top. Swap the two ids in place instead: they are all that those two and process.nextTick() read. executionAsyncResource() is the only reader of the stack: the scopes that skip it form a chain in AsyncHooks, counted in a new field, kLazyScopes, and JS asks C++ for the innermost one only while that count is not zero. The checks for a corrupted stack stay. Refs: nodejs/performance#24 Signed-off-by: Nigro Simone <nigro.simone@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With no async hook and no
executionAsyncResource()user, every InternalCallbackScope pushes and pops the async ids on the stack, only forexecutionAsyncId()andtriggerAsyncId()to read the top. This swaps the two ids in place instead: they are all that those two andprocess.nextTick()read, so the readers pay nothing.executionAsyncResource()is the only reader of the stack. The scopes that skip it form a chain in AsyncHooks, counted in a new fieldkLazyScopes, and JS asks C++ for the innermost one only while that count is not zero. The checks for a corrupted stack stay: test/async-hookstest-improper-orderandtest-emit-*-on-destroyedfail without them, because the main script runs in a scope that starts before any hook.compare.js on
napi/make_callback(thetypecases of #66326), 30 runs, Linux x64, one core, with #66395 and #66500 underneath:MakeCallback goes from 128.7 to 119.5 ns at n=1e7. The nextTick and AsyncLocalStorage benchmarks do not move. test/async-hooks, the ALS tests (also with
--no-async-context-frame) and the new addon test pass.Draft because the new field and the chain are a design choice to agree on first, see nodejs/performance#24.
Disclosure: I used Opus 5.5 (Max) as coding assistant