-
Notifications
You must be signed in to change notification settings - Fork 3
transfer() semantics around preserving resizability #4
Comments
My main use case for So to me, I think B > C >> A. From my perspective, it seems like a big win if a method named |
Interesting! Thanks for your perspective. I plan to have a quick discussion at the next plenary. |
Result from November 2022 TC39 is to split out transfer() into its own proposal and demote it to Stage 2 to further explore the design space. Some variant of (B) above seems to be the most popular option. Other ideas that were floated:
@jridgewell's idea sgtm from an API design perspective, I need to think more about the implementation implications of this. @mhofman's idea about CoW ABs give me pause about implementation complexity and breaking the "ABs should be implementable as having fixed data pointers from construction, for the sake of security" design goal. |
The upshot of #4 is that |
This method will be explored in its own proposal. See #113.
This method will be explored in its own proposal. See #113.
https://bugs.webkit.org/show_bug.cgi?id=248484 rdar://102775650 Reviewed by Mark Lam. ArrayBuffer#transfer's semantics is still under discussion, and TC39 decided separating this out from the rest of resizable ArrayBuffer, and creating a new proposal for ArrayBuffer#transfer. We disable ArrayBuffer#transfer to follow to this. [1]: https://github.com/tc39/proposal-resizablearraybuffer/issues/113 * JSTests/ChakraCore/test/typedarray/arraybufferType.baseline-jsc: * JSTests/stress/v8-harmony-arraybuffer-transfer.js: * JSTests/test262/config.yaml: * Source/JavaScriptCore/runtime/JSArrayBufferPrototype.cpp: (JSC::JSArrayBufferPrototype::finishCreation): * Source/JavaScriptCore/runtime/OptionsList.h: Canonical link: https://commits.webkit.org/257162@main
The spun out proposal repo is up at https://github.com/tc39/proposal-arraybuffer-transfer. Closing this thread; please have further discussions in that repo. |
Also add https://html.spec.whatwg.org/multipage/structured-data.html to that list. We'll want this to preserve resizability:
Looks like I misread the explainer. 😅 As currently written,
transfer()
always returns a non-resizableArrayBuffer
.Should we changeI suppose this answers one of the open questions on this proposal:transfer()
to preserve resizability? Or should there be a different method (or option fortransfer()
) which does that?So yes, there are compelling use cases! 😁
ArrayBuffer
while doing a BYOB read, and then returns ownership back to the user once it's filled the buffer. If the input buffer is resizable, we'll want to preserve that property in the returned buffer.ArrayBuffer
between realms (throughpostMessage()
) should also preserve resizability. One possible use case could be making readable byte streams transferable, allowing the BYOB request to be transferred and filled by another realm. (At the moment, transferring a readable byte stream results in a "default" readable stream without BYOB support, but we should be able to extend the Streams spec to allow for BYOB.)_Originally posted by @MattiasBuelens in #3
Splitting off this question into its own issue. Currently
transfer()
always produces a fixed-length ArrayBuffer.It seems good to give it the additional capability to produce resizable buffers. I'd like to defer this to a follow-on proposal, but there is some future proofing to do here.
The two interlinked API design questions I think are:
transfer()
what kind of ArrayBuffer to return?transfer()
preserve the resizability of its receiver by default? If so, how do you override that default behavior?One natural way to address (1) is to add an options bag to
transfer()
, mirroring what the constructor accepts:transfer(newLen, { maxByteLength })
. If a{ maxByteLength }
options bag is passed, thentransfer
returns a resizable buffer, just like the constructor.However, this design cannot also satisfy (2) if it is decided (2) should preserve resizability by default. Preserving by default means that if the
{ maxByteLength }
options bag is not passed, that it gets this value from the receiver. But if that's the case, there's no way to telltransfer
to make a fixed-length ArrayBuffer from a resizable one. And moving a resizable buffer to a fixed one is one of the original use cases: to do a zero-copy move and also free up the reserved virtual memory after resizing is no longer needed.There are a few choices moving forward:
A. Stick with the current design of
transfer()
, i.e. always return fixed buffers. When we extendtransfer()
to produce resizable buffers, an explicit options bag must always be passed. It does not preserve resizability by default.B. Make
transfer()
preserve resizability if the options bag is undefined. Since this means you cannot transfer from resizable into a fixed length buffer, add a new methodfix()
(name up for bikeshed).C. Have a
transfer()
preserve resizability if both parameters are undefined. That is, make the nullarytransfer()
a special overload that perform a "move as is".transfer(newLen)
always produces a fixed-length buffer ofnewLen
, andtransfer(newLen, { maxByteLength }
) always produces a resizable buffer.I think I prefer A > C >>> B. Thoughts?
The text was updated successfully, but these errors were encountered: