-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
buffer: revert GetBackingStore optimization in API #44579
base: v18.x-staging
Are you sure you want to change the base?
Conversation
8df27df
to
5ca238a
Compare
maybe hot take: only land this commit on 18.x and keep the optimization moving forward. |
I agree. I don't think it is worth giving up this optimization going forward for such an edge case. |
IMHO returning a I am also for targeting Node.js 18 with this PR and for keeping the change on the main branch. Similar discussion: #44543 |
@nodejs/releasers Should we change the base branch of this PR to |
Yes, if you want to keep the original change on |
In an earlier PR, I replaced a lot of instances of `GetBackingStore()->Data()` with `Data()`. Apparently these two are not equivalent in the case of zero-length buffers: the former returns a "valid" address, while the latter returns `NULL`. At least one library in the ecosystem (see the referenced issue) abuses zero-length buffers to wrap arbitrary pointers, which is broken by this difference. It is unfortunate that every library needs to take a performance hit because of this edge-case, and somebody should figure out if this is actually a reasonable contract to uphold long-term. I have not traced down exactly why this divergence occurs, but I have verified that reverting this line fixes the referenced issue. Refs: nodejs#44080 Fixes: nodejs#44554
5ca238a
to
c947744
Compare
src/node_buffer.cc
Outdated
return static_cast<char*>(ui->Buffer()->GetBackingStore()->Data()) + | ||
|
||
ui->ByteOffset(); |
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.
return static_cast<char*>(ui->Buffer()->GetBackingStore()->Data()) + | |
ui->ByteOffset(); | |
return static_cast<char*>(ui->Buffer()->GetBackingStore()->Data()) + | |
ui->ByteOffset(); |
(Not sure what indentation will make format-cpp happy, though.)
Thanks all. I'm fine with the change only landing on the release branch. I fixed the spurious newline which snuck in somehow. |
99d004e
to
6dc0382
Compare
Hello from Deno! I did some checking into this in the Deno codebase, specifically to do with the FFI / C API there. I can confirm that the same issue occurs there as well. However, we have an extra wrinkle to this, which necessitates opening an issue to track and fix this bug / feature. The Deno FFI API uses the V8 Fast API for binding foreign C functions into JavaScript functions. The API offers ArrayBuffers / ArrayBufferViews to the native C function as a struct with a If you already have a V8 issue open about this, I would like a link. Otherwise, I'll make one shortly. |
68cca1e
to
2098d7a
Compare
2098d7a
to
bac6b7d
Compare
7351221
to
fcfde34
Compare
ef85828
to
490fc00
Compare
This should now be fixed in the most recent V8 versions. |
In an earlier PR, I replaced a lot of instances of
GetBackingStore()->Data()
withData()
. Apparently these two are not equivalent in the case of zero-length buffers: the former returns a "valid" address, while the latter returnsNULL
. At least one library in the ecosystem (see the referenced issue) abuses zero-length buffers to wrap arbitrary pointers, which is broken by this difference. It is unfortunate that every library needs to take a performance hit because of this edge-case, and somebody should figure out if this is actually a reasonable contract to uphold long-term.I have not traced down exactly why this divergence occurs, but I have verified that reverting this line fixes the referenced issue.
Refs: #44080
Fixes: #44554