Skip to content

node::Buffer::New is 4x slower than V8 APIs #44111

Description

@kvakil

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?

  1. Clone this repo.
  2. Run npm install.
  3. Run node v8_buffers.js, which uses v8::ArrayBuffer::NewBackingStore + v8::ArrayBuffer::New.
  4. Run node node_buffers.js, which uses node::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:

$ node node_buffers.js 
1000000
nodeBuffers: 1.649s
$ node v8_buffers.js 
1000000
rawArrayBuffers: 432.881ms

It is even worse (~6x) if you use time to include the GC finalizer time:

$ \time node node_buffers.js 
1000000
nodeBuffers: 1.657s
2.99user 0.41system 0:02.68elapsed 127%CPU (0avgtext+0avgdata 648340maxresident)k
0inputs+0outputs (0major+332498minor)pagefaults 0swaps
$ \time node v8_buffers.js 
1000000
rawArrayBuffers: 430.123ms
0.54user 0.12system 0:00.60elapsed 111%CPU (0avgtext+0avgdata 308632maxresident)k
0inputs+0outputs (0major+71241minor)pagefaults 0swaps

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bufferIssues and PRs related to the buffer subsystem.node-apiIssues and PRs related to Node-API.performanceIssues and PRs related to the performance of Node.js.

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions