DescriptionThis is the pure-Chromium side for the WebKit patch detailed at https://bugs.webkit.org/show_bug.cgi?id=65209 . This patch can compile independently of that WebKit patch; it contains some temporary preprocessor blocks to accomplish this.
The Structured Clone algorithm describes an interface for Transferable objects (http://www.whatwg.org/specs/web-apps/current-work/complete/common-dom-interfaces.html#transferable-objects). Currently the only official Transferable object is the MessagePort, but ArrayBuffers are expected to be sanctioned as such soon. This is particularly important for Chrome because it will allow for cheap (copy-free) passing of ArrayBuffer data to and from in-process dedicated workers (once these land). ArrayBuffers are used heavily with WebGL; clients of that API have noted that they have found the existing implementation of message passing to be a little slow.
Imagine that we're trying to transfer an ArrayBuffer to a dedicated worker.
- JS calls postMessage(msg, [buffer]), where buffer is mentioned somewhere in msg.
- The ArrayBuffer backing the JS buffer is a Transferable; we transfer it out, getting back a TransferableReceipt that we can later exchange for an equivalent ArrayBuffer. The original Transferable is marked as closed.
- msg is serialized (with buffer being maintained as an external reference). The serialized msg and the TransferableReceipt for buffer are passed around together.
- Since we never touch IPC, we never need to copy the underlying array data; under the covers, it belongs to the TransferableReceipt.
- When it comes time to deserialize msg in the context of the destination dedicated worker, we exchange buffer's TransferableReceipt back for its promised Transferable-- an ArrayBuffer that takes control of the original array's memory.
If it turns out that the message needs to cross an IPC boundary, some TransferableReceipts will need to be flattened-- that is, the IPC system will redeem them and paste the data they contain to the beginning of the serialized message. Note that certain Transferables have special semantics (like MessagePorts) under which it either doesn't make sense or isn't useful to clone the objects in this way. This flattening happens just before the message gets sent out (because at the time the message is generated there isn't a clear way to determine that it will eventually need to travel across an IPC boundary).
Patch Set 1 #Patch Set 2 : Compile independently of WebKit changes. #Patch Set 3 : Rebase. #
Total comments: 2
Patch Set 4 : Fix a style issue. #Patch Set 5 : Rebase; some fixes. #Patch Set 6 : Rebase. #Patch Set 7 : Flatten everywhere necessary. #Patch Set 8 : Update for interface changes. #
Messages
Total messages: 5 (0 generated)
|