-
Notifications
You must be signed in to change notification settings - Fork 29.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
async_hooks: move to lazy destroy hook registration in AsyncResource #32429
Conversation
@vdeturckheim is it too much to ask you to take a look at this PR? |
@puzpuzpuz it's on the list rn, but I need a bit more time as I have a lot to do in the next few days. |
I didn't know that. Thanks for the clarification! |
doc/api/async_hooks.md
Outdated
@@ -685,6 +685,8 @@ asyncResource.triggerAsyncId(); | |||
object is garbage collected. This usually does not need to be set (even if | |||
`emitDestroy` is called manually), unless the resource's `asyncId` is | |||
retrieved and the sensitive API's `emitDestroy` is called with it. | |||
When set to `false`, automatic `emitDestroy` behavior will only take |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will probably need to rebase this part over https://github.com/nodejs/node/pull/32514/files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the heads up!
As that PR is now merged, I have rebased this PR and slightly changed this new sentence in the AsyncResource
doc, so it's more consistent with #32514.
61f8496
to
65a44dd
Compare
CI: https://ci.nodejs.org/job/node-test-pull-request/30474/ (:heavy_check_mark:) |
Landed in 561dda2 |
PR-URL: #32429 Reviewed-By: Gerhard Stöbich <[email protected]> Reviewed-By: Vladimir de Turckheim <[email protected]>
PR-URL: #32429 Reviewed-By: Gerhard Stöbich <[email protected]> Reviewed-By: Vladimir de Turckheim <[email protected]>
PR-URL: #32429 Reviewed-By: Gerhard Stöbich <[email protected]> Reviewed-By: Vladimir de Turckheim <[email protected]>
PR-URL: #32429 Reviewed-By: Gerhard Stöbich <[email protected]> Reviewed-By: Vladimir de Turckheim <[email protected]>
Adds a check into
AsyncResource
constructor, so thatregisterDestroyHook
only gets called whenrequireManualDestroy
isfalse
and there are no activedestroy
hooks (previously the check only includedrequireManualDestroy
value). As below benchmark shows this eliminates a certain overhead related with additional tracking of these objects as a part of GC cycle.This scenario is important considering
AsyncLocalStorage
API which only usesinit
hooks.Important note. Obviously, this PR changes the behavior in the following edge case: previously when an
AsyncResource
was created (but not yet destroyed) before enabling the firstdestroy
hook, the hook would be called for the resource. With this change it's not called.Related discussion thread: petkaantonov/bluebird#1472 (comment)
cc @addaleax @vdeturckheim @Qard @Flarna (sorry for such long CC list, but I think all of you might be interested)
Benchmarks
Before this change:
After this change:
Note:
trackingEnabledWithDestroyHook
scenario was added as a replacement for the oldtrackingEnabled
scenario.Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes