-
Notifications
You must be signed in to change notification settings - Fork 18
More details on how this interacts with WebAssembly.Memory #5
Comments
My current thinking, which is still a bit handwavy:
|
This makes sense to me. I was assuming we'd replace the const module = new WebAssembly.Module(bytes); // some module that exports memory.
const instance = new WebAssembly.Instance(module);
const memory = instance.exports.memory; We wouldn't want to add a new flag to the wasm binary bytestream for this. I suppose you could imagine another parameter to So if we have both
Yes, this sounds right to me. |
It'd certainly be nicer if we could replace the property. My impression is that doing so would create minor observable changes, but to detect them you'd have to writing somewhat unusual code. Is that impression accurate? |
Well the major change is that currently a buffer object would be detached if the memory is grown, which is the issue we're trying to fix in the first place. I think it would be unusual to rely on that, but I could see doing it for debugging reasons maybe. |
Apologies if this has already been discussed elsewhere. In WebAssembly, memory may only be grown in units of "page size" (multiples of 2^16 bytes). Some implementation schemes rely on this and could not support a byte-granularity growth. For example, this approach by V8 relies on protecting/unprotecting OS pages to simulate memory growth and eliminate explicit bounds checks. My understanding is that we want to be able to expose Wasm memories as GrowableSharedArrayBuffer in JavaScript. Currently the JS grow instruction is sketched as having byte granularity. Is it intended that the buffer should be grown exactly according to the grow argument, or is it permitted for implementations to grow some implementation-defined amount more? I could alternatively imagine the GrowableSharedArrayBuffer keeping an explicitly checked byteLength even if the underlying Wasm memory needs to be grown more. |
Good question. This is the resize() analogue to #18. The wasm behavior can be implemented in the current spec draft by something like throwing on growth requests from the JS side that would result in a non-page size multiple for wasm-vended RABs. Would this be too cumbersome? The other option is as you say, permit implementations to round resize requests accordingly. For regular JS-originated RABs, I see some value in not rounding, otherwise some class of applications would need to again track their own length. The cost to the developer is that they'll need to internalize different throwing or rounding behaviors depending on how the RAB was vended. Given that wasm already has this restriction, this difference needs be internalized regardless. |
Ah, as an OOM error? Conceptually it seems a little odd to me, but I have near-zero context on whether there would be any real practical implications. It might lead to a de-facto restriction where generic libraries over RABs only ever attempt to grow by "Wasm-blessed" values, just in case they're passed a RAB backed by a Wasm memory. |
All the specification would say is that it's a TypeError. The message contents and kind of error isn't that granular in JS, so it also seems fine to me for those errors to throw for misalignment. |
I'm wondering if it's actually desirable to support calling the mutating methods on wasm-created RABs. We already disallow detaching for ABs, so
Is it workable to include all that? |
From the spec draft's POV, certainly for For |
I think it's important to get a concrete answer on this question, ideally around the time this proposal goes to Stage 3. We should bring a change to the WebAssembly/JS API formalizing the change to the Wasm CG. |
What question in particular? Whether As for sequencing, are you requesting that the Wasm/JS API integration changes be gotten consensus for before stage 3, or immediately after ("around the time") of stage 3? |
Arguably #5 (comment) was plenty concrete, but still, I'm a bit disappointed if this topic hasn't been raised to Wasm CG. I raised the interaction as a concern at the previous TC39 meeting, and there have been a couple CG meetings since then (and the WebAssembly/spec repo is always open to file an issue). I don't think we need very strong consensus in Wasm CG before Stage 3 in TC39, but ideally we've discussed it with them and have something of a common idea. This is typically the state that we ask for with HTML integration for JS proposals which have a lot of issues there. |
Looks like the next Wasm CG meeting is on the 16th. I'll file a bug on the Wasm repo. |
A note that the integration PR is at WebAssembly/spec#1300 and reached Phase 1 on March 30. |
The proposal has reached stage 4; further questions should likely go to the discourse. |
Thanks for working on this, I like the direction this is going! I have a few questions about how this proposal will integrate with WebAssembly.
buffer
accessor will always return the sameResizableArrayBuffer
?ArrayBuffer
should be used (perhaps if the maximum memory size isn't provided)?ResizableArrayBuffer
is shrunk? Do we disallow that operation?The text was updated successfully, but these errors were encountered: