Skip to content
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

Add v8::ArrayBuffer::Data #1068

Merged
merged 2 commits into from
Sep 16, 2022
Merged

Conversation

littledivy
Copy link
Member

https://v8.github.io/api/head/classv8_1_1ArrayBuffer.html

More efficient shortcut for GetBackingStore()->Data(). The returned pointer is valid as long as the ArrayBuffer is alive.

@littledivy littledivy enabled auto-merge (squash) September 16, 2022 06:42
Copy link
Contributor

@bnoordhuis bnoordhuis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One caveat to be aware of: nodejs/node#44554. Probably doesn't matter for deno though.

@littledivy littledivy merged commit 31291f6 into denoland:main Sep 16, 2022
@billywhizz
Copy link

billywhizz commented Sep 16, 2022

this looks nice. i'll see if can measure any difference in perf. one experiment i tried in just-js actually worked but one thing i was not sure about is whether that address will change when GC is under memory pressure - i assume V8 GC can move heap allocated ArrayBuffer backing data if heap is fragmented etc.?

https://github.com/just-js/modules/blob/main/memory/memory.cc#L39

I have never seen this happen in practice with the just-js hack and it can also be circumvented by externalising the arraybuffer so we are in control of the backing data and ensuring it doesn't get moved/freed.

another benefit of doing something like this is that passing an integer in as id for a buffer is cheaper than passing an arraybuffer from JS to C++. at least last time i checked it was.

@bnoordhuis
Copy link
Contributor

Good point about arraybuffers moving around after GC. I thought rusty_v8 had that disabled but no.

It's controlled by the v8_typed_array_max_size_in_heap setting. rusty_v8 inherits that from v8/BUILD.gn where it's set to 64. Node explicitly sets it to 0 and so should rusty_v8, most likely.

@billywhizz
Copy link

thanks @bnoordhuis. i wonder could that be the source of some of these panics and segfaults we are seeing? 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants