-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
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
base: main
Are you sure you want to change the base?
Conversation
|
Review requested:
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #60558 +/- ##
==========================================
- Coverage 88.54% 88.53% -0.01%
==========================================
Files 704 704
Lines 207843 207847 +4
Branches 40044 40042 -2
==========================================
- Hits 184028 184026 -2
+ Misses 15858 15848 -10
- Partials 7957 7973 +16
🚀 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 |
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
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