-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
node::Buffer::New
is 4x slower than V8 APIs
#44111
Comments
I would be reluctant to put a lot of effort into improving performance of a feature when there's a better, faster language built-in already available. We probably should and can deprecate the native Buffer API(s). 🙂 That being said, for the comparison to be a bit fairer, I think the V8 benchmark should create Uint8Arrays, not just ArrayBuffers, because that's the direct equivalent of Buffer. |
Any thoughts about how a deprecation should interact with I looked at some Github search results, and I haven't actually been able to find anyone relying on the finalizer to call back into Javascript. I wonder if it would be possible to expose a different function like |
I think deprecating or discouraging the use of
Yeah … not great. I introduced this in c1ee70e, with a commit message that hopefully explains the choice well enough.
I’m pretty sure we’ve had bug reports about this here in the Node.js repository. But either way, this can be a pretty subtle breaking change that can’t easily be put through a deprecation cycle.
I think this would be a good idea anyway, yes 👍 One could call it |
For node-api finalizers to be able to calling into JavaScript or how can we improve the condition here by providing an "eager finalization" without the ability to evaluate JavaScript, this is the problem tracked at #44071. I believe the problem is not limited to the finalizer of external_array_buffer in node-api. |
I'll open a PR to add a note in the documentation.
Right, completely agreed that changing/deprecating the existing semantics is a non-starter. But I suspect that most people aren't using the delayed finalizer, and they would benefit from the eager finalizer. As another data point, I believe both
Thanks for pointing this out. I guess that adding |
no more than just me that think we should stop using Buffer: #41588 |
On a related note, So to me, deprecating and eventually removing these methods makes sense, as right now they are problematic to use if you want a cross runtime compatible native module |
Add a micro benchmark for external buffer creation. PR-URL: #54877 Refs: #53804 Refs: #44111 Reviewed-By: Gabriel Schulhof <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
Add a micro benchmark for external buffer creation. PR-URL: #54877 Refs: #53804 Refs: #44111 Reviewed-By: Gabriel Schulhof <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
Add a micro benchmark for external buffer creation. PR-URL: #54877 Refs: #53804 Refs: #44111 Reviewed-By: Gabriel Schulhof <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
Add a micro benchmark for external buffer creation. PR-URL: #54877 Refs: #53804 Refs: #44111 Reviewed-By: Gabriel Schulhof <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
Add a micro benchmark for external buffer creation. PR-URL: #54877 Refs: #53804 Refs: #44111 Reviewed-By: Gabriel Schulhof <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
Add a micro benchmark for external buffer creation. PR-URL: #54877 Refs: #53804 Refs: #44111 Reviewed-By: Gabriel Schulhof <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
Add a micro benchmark for external buffer creation. PR-URL: #54877 Refs: #53804 Refs: #44111 Reviewed-By: Gabriel Schulhof <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
Add a micro benchmark for external buffer creation. PR-URL: #54877 Refs: #53804 Refs: #44111 Reviewed-By: Gabriel Schulhof <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
Add a micro benchmark for external buffer creation. PR-URL: nodejs#54877 Refs: nodejs#53804 Refs: nodejs#44111 Reviewed-By: Gabriel Schulhof <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
Add a micro benchmark for external buffer creation. PR-URL: nodejs#54877 Refs: nodejs#53804 Refs: nodejs#44111 Reviewed-By: Gabriel Schulhof <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
Version
v19.0.0-pre
Platform
Linux 19-Ubuntu SMP Wed Jun 22 17:44:56 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Subsystem
buffer
What steps will reproduce the bug?
npm install
.node v8_buffers.js
, which usesv8::ArrayBuffer::NewBackingStore
+v8::ArrayBuffer::New
.node node_buffers.js
, which usesnode::Buffer::New
.How often does it reproduce? Is there a required condition?
always
What is the expected behavior?
Performance of
node::Buffer::New
should be comparable to the native V8 APIs.What do you see instead?
It's around 4x slower:
It is even worse (~6x) if you use
time
to include the GC finalizer time:Additional information
I know that
node::Buffer::New
does more than the V8 APIs, so of course it is slower. Especially a lot of the finalizer stuff seems to be pretty high overhead. But 4x feels quite a bit slower, and I suspect that there is some room for improvement.Attached are two
perf script
profiles:v8_buffers.gz
node_buffers.gz
The text was updated successfully, but these errors were encountered: