Skip to content

perf(ext/node): elide async_hooks emit in timers when no hooks registered#33355

Merged
bartlomieju merged 2 commits into
denoland:mainfrom
nathanwhit:skip-hooks-emit
Apr 22, 2026
Merged

perf(ext/node): elide async_hooks emit in timers when no hooks registered#33355
bartlomieju merged 2 commits into
denoland:mainfrom
nathanwhit:skip-hooks-emit

Conversation

@nathanwhit

@nathanwhit nathanwhit commented Apr 22, 2026

Copy link
Copy Markdown
Member

Match node: the Timeout ctor's emitInit and the per-fire emitBefore/emitAfter/emitDestroy calls only matter when async_hooks are active, but the machinery (try/finally, empty-array loop, lookupPublicResource) runs regardless. Gate all of them on enabledHooksExist().

increases throughput by about 4.5% on hello world

Disclosure: used claude

…ered

Match node: the Timeout ctor's emitInit and the per-fire
emitBefore/emitAfter/emitDestroy calls only matter when async_hooks
are active, but the machinery (try/finally, empty-array loop,
lookupPublicResource) runs regardless. Gate all of them on
enabledHooksExist().

Also drop ObjectDefineProperty for the _timer slot — direct
assignment is fine and this runs per setTimeout on keep-alive
HTTP connections.

@bartlomieju bartlomieju left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, simple and significant win

@bartlomieju
bartlomieju merged commit 9680445 into denoland:main Apr 22, 2026
221 of 223 checks passed
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.

2 participants