-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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: faster AsyncResource#bind() #43065
Conversation
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
Looks like I submitted too soon again here. While |
Setting this as "ready for review" again. It's now always doing an |
This comment was marked as outdated.
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
@mcollina |
Here's a benchmark run: https://ci.nodejs.org/job/benchmark-node-micro-benchmarks/1136/ |
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.
Closing since #46432 precludes this. |
theFunctionPrototypeBind
preserveslength
, andasyncResource
property can just be set normally, avoiding the costly call toObjectDefineProperties
.In thereducing it to a singlethisArg === undefined
case,ObjectDefineProperty
stillhas 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):(Expand here for old/incorrect benchmark.)
cc @nodejs/async_hooks