Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34.4k
buffer: revert GetBackingStore optimization in API#44579
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:v18.x-staging
Are you sure you want to change the base?
Uh oh!
There was an error while loading. Please reload this page.
Conversation
8df27df to 5ca238aComparedevsnek commented Sep 9, 2022
maybe hot take: only land this commit on 18.x and keep the optimization moving forward. |
mscdex commented Sep 9, 2022
I agree. I don't think it is worth giving up this optimization going forward for such an edge case. |
tniessen commented Sep 9, 2022
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 |
tniessen commented Sep 12, 2022
@nodejs/releasers Should we change the base branch of this PR to |
targos commented Sep 12, 2022
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#44080Fixes: nodejs#44554
5ca238a to c947744Comparetniessen commented Sep 12, 2022
| returnstatic_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.
| returnstatic_cast<char*>(ui->Buffer()->GetBackingStore()->Data()) + | |
| ui->ByteOffset(); | |
| returnstatic_cast<char*>(ui->Buffer()->GetBackingStore()->Data()) + | |
| ui->ByteOffset(); |
(Not sure what indentation will make format-cpp happy, though.)
kvakil commented Sep 14, 2022 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
Thanks all. I'm fine with the change only landing on the release branch. I fixed the spurious newline which snuck in somehow. |
nodejs-github-bot commented Sep 14, 2022
99d004e to 6dc0382Compareaapoalas commented Nov 14, 2022
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. |
aapoalas commented Nov 14, 2022
68cca1e to 2098d7aCompare2098d7a to bac6b7dCompareef85828 to 490fc00Compareaapoalas commented Mar 11, 2024 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
This should now be fixed in the most recent V8 versions. |
This issue/PR was marked as stalled, it will be automatically closed in 30 days. If it should remain open, please leave a comment explaining why it should remain open. |
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