Skip to content

async_hooks: speed up AsyncLocalStorage.run() - #67805

Closed
IlyasShabi wants to merge 1 commit into
nodejs:mainfrom
IlyasShabi:ishabi/als-run-perf
Closed

IlyasShabi wants to merge 1 commit into
nodejs:mainfrom
IlyasShabi:ishabi/als-run-perf

Conversation

@IlyasShabi

Copy link
Copy Markdown
Member

This PR aims to improve the performance of AsyncLocalStorage.prototype.run() by:

  • Copy the previous AsyncContextFrame using MapPrototypeForEach instead of super(previous) to avoid iterator and array allocations.
  • Restore the prior AsyncContextFrame directly on run() exit instead of calling this.enterWith(prior) when the frame wasn't replaced or mutated via disable() to avoid a second frame copy per run().

Local benchmark

                                                                             confidence improvement accuracy (*)   (**)  (***)                                                                                                               
    async_hooks/async-local-storage-run-nested.js n=100000 storageCount=0          ***    116.78 %       Β±3.62% Β±4.84% Β±6.35%                                                                                                                
    async_hooks/async-local-storage-run-nested.js n=100000 storageCount=1          ***     78.43 %       Β±3.01% Β±4.02% Β±5.24%                                                                                                                
    async_hooks/async-local-storage-run-nested.js n=100000 storageCount=10         ***     98.31 %       Β±3.62% Β±4.86% Β±6.41%                                                                                                                
    async_hooks/async-local-storage-run-nested.js n=100000 storageCount=100        ***     97.98 %       Β±2.37% Β±3.16% Β±4.13%

Signed-off-by: ishabi <ilyasshabi94@gmail.com>
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/performance

@nodejs-github-bot nodejs-github-bot added async_local_storage Issues and PRs related to the AsyncLocalStorage API. needs-ci PRs that need a full CI run. labels Nov 26, 2026
@gurgunday

gurgunday commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Isn't this similar to: #67396

Mostly same in fact πŸ˜„

@IlyasShabi

Copy link
Copy Markdown
Member Author

Yees the same thing! Sorry didn't see your PR πŸ˜“

@IlyasShabi IlyasShabi closed this Nov 26, 2026
@IlyasShabi
IlyasShabi deleted the ishabi/als-run-perf branch November 27, 2026 08:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

async_local_storage Issues and PRs related to the AsyncLocalStorage API. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants