-
-
Notifications
You must be signed in to change notification settings - Fork 34.2k
lib: use fastbuffer for empty buffer allocation #60558
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
Conversation
|
Review requested:
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #60558 +/- ##
==========================================
- Coverage 88.54% 88.47% -0.07%
==========================================
Files 704 701 -3
Lines 207843 207793 -50
Branches 40044 40009 -35
==========================================
- Hits 184028 183851 -177
- Misses 15858 15999 +141
+ Partials 7957 7943 -14
🚀 New features to boost your workflow:
|
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.
This bypasses the validation logic and is consequently faster
Is that measurable? If yes, would special-casing Buffer.alloc(0) or otherwise improving Buffer.alloc be faster/cleaner instead?
As it's also used in other places, e.g. undici
Yes. buffers/fast-buffer.js
buffers/fast-buffer.js operation="fastbuffer" n=1000000: 47,834,970.118450865
buffers/fast-buffer.js operation="bufferalloc" n=1000000: 33,173,868.757805813I'd oppose adding this logic to Edit: However, I think more work could be done to improve the performance of validators in Node.js like |
|
The issue with the current approach is that it doesn't optimize e.g. code in undici (or anything in userspace) Also I'm not sure Will check shortly |
ChALkeR
left a comment
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.
Ok, this actually seems to be better than attempting to improve alloc
|
@aduh95 sorry for the ping, could you |
Why don't you do it yourself? |
@aduh95 I'm not a collaborator unfortunately, I can't request it :( |
|
Should I add the benchmark? I thought it would be unnecessary in this case |
|
@aduh95 I added the benchmark if you'd like to verify it's faster Edit: but it's not gonna show a difference between main and this branch, it's only to see |
This reverts commit aa2fca1.
|
It won't work actually since it requires expose internals in the benchmark, but you can verify by looking at the code path I provided or running the benchmark directly |
|
Ah sorry, I didn't look closely enough, it's certainly fine not to add the benchmark. Given that 3cf7088...10bb3e6 shows no changes, and there's already a green CI and approvals for 3cf7088, I think this is ready to land as is. |
|
Landed in 2271d2d |
PR-URL: nodejs#60558 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
PR-URL: #60558 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
As in other places, we don't need to call Buffer.alloc(0), which validates the length and calls FastBuffer anyway, when we're creating an empty Buffer
This bypasses the validation logic and is consequently faster