GeezerVison is showing github.com — async_hooks: faster AsyncResource#bind() by bengl · Pull Request #43065 · nodejs/node
Conversation
bengl
commented
May 12, 2022
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
FunctionPrototypeBind preserves length, and the asyncResource property can just be set normally, avoiding the costly call to ObjectDefineProperties. In the thisArg === undefined case, reducing it to a single ObjectDefineProperty still has tangible performance gain.
I added a benchmark and here is the output on my machine (the ./node-master result is without this commit, and the ./node result is with it):
$ ./node benchmark/async_hooks/async-resource-bind.js
async_hooks/async-resource-bind.js option="withThisArg" n=1e+100: 5.619836901644185e+99
async_hooks/async-resource-bind.js option="withoutThisArg" n=1e+100: 5.96856136341294e+99
$ ./node-master benchmark/async_hooks/async-resource-bind.js
async_hooks/async-resource-bind.js option="withThisArg" n=1e+100: 1.5451341226758954e+99
async_hooks/async-resource-bind.js option="withoutThisArg" n=1e+100: 1.605511858099379e+99
(Expand here for old/incorrect benchmark.)
$ ./node benchmark/async_hooks/async-resource-bind.js
async_hooks/async-resource-bind.js option="withThisArg" n=1e+100: 4.6615746235960295e+100
async_hooks/async-resource-bind.js option="withoutThisArg" n=1e+100: 5.939287298590602e+100
$ ./node-master benchmark/async_hooks/async-resource-bind.js
async_hooks/async-resource-bind.js option="withThisArg" n=1e+100: 1.6248803889798304e+99
async_hooks/async-resource-bind.js option="withoutThisArg" n=1e+100: 1.6487041313302313e+99
cc @nodejs/async_hooks
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
bricss and metcoder95 reacted with thumbs up emoji
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
bengl
commented
May 12, 2022
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|
Looks like I submitted too soon again here.
While FunctionPrototypeBind does preserve length, it's preserving the length of runInAsyncScope, and not the fn in question. It will need to preserve the length the same way as the other code path, but I since I suspect that it will still be significantly faster, I'm going to leave this open in Draft mode until I can clean it up (hopefully in the next day or two).
|
mcollina reacted with heart emoji
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Setting this as "ready for review" again. It's now always doing an ObjectDefineProperty, but that's still about a 3.7x improvement on my machine.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as outdated.
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.
LGTM
How did you found this was a bottleneck? :D
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
@mcollina .bind() is a pretty hot path with a lot of the new changes (and some upcoming ones) in our APM tracing library, so I was investigating it directly.
|
mcollina and tonivj5 reacted with heart emoji
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced May 14, 2022
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
value: this,
|
|
|
writable: true,
|
|
|
}
|
|
|
ObjectDefineProperty(bound, 'length', {
|
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.
Why not just stop doing this completely? This is only one of the cases needed to preserve the original functionality as the function could also have other properties or symbols attached to it for example, and those wouldn't be copied. Maybe the best approach then would be to copy nothing and leave it to the user to decide what needs copying. Then the implementation will be as fast as it can be and will only become slower if the user decides that copying properties is needed.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Closing since #46432 precludes this.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Labels
async_hooks
Issues and PRs related to the async hooks subsystem.
needs-ci
PRs that need a full CI run.
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.
|