-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
buffer: let Buffer.of use heap #60503
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
1e926c5 to
42a4e92
Compare
42a4e92 to
1a8aac1
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #60503 +/- ##
==========================================
+ Coverage 88.05% 88.57% +0.52%
==========================================
Files 704 704
Lines 207857 207858 +1
Branches 39964 40044 +80
==========================================
+ Hits 183030 184117 +1087
+ Misses 16806 15789 -1017
+ Partials 8021 7952 -69
🚀 New features to boost your workflow:
|
|
I'm not a huge fan of this approach - avoiding But anyway, maybe it could be a very targeted change for |
|
@gurgunday there is no significant difference on 1024/2048 according to the bench, but significant improvement on <=64 (which is the case almost always).
That's why I left a comment there explaining the difference 🙃 |
|
What's up with timerify/histogram tests?
That doesn't seem related and looks like an existing bug Upd: ah, #54803 |
See also #60372.
This is a somewhat less performant version than that PR, but significantly faster than
mainand is non semver-major (so it can be backported) and does not need doc changes.Buffer.ofis usually used on small static sizes (checked with GitHub codesearch)The assumption that
createUnsafeBuffer(size)is faster thannew Uint8Array(size)/new FastBuffer(size)is incorrect for small sizes, as the latter does not call our allocator at all when it can go to heap, and the former is always an alloc.Not letting it go to heap is hurting performance, direct allocations are slow.
See #26301 for context
But even past the
v8_typed_array_max_size_in_heapsize (which is 64 bytes in the default config), this is still not worse than the old version way past expectedBuffer.ofsizesBefore:
After:
For comparison, #60372 (even faster, but does that via pooling):
Realistically, sizes 0-8 are most important.
Benchmark code (taken from #60372 with some adjustments):