-
Notifications
You must be signed in to change notification settings - Fork 45
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
Transferable objects #23
Comments
Hi -- sorry for this crazily late reply! I'll have a deeper look into this when time permits, but it definitely looks like something operative should support. I think I did consider it right at the beginning but I couldn't figure out a clear path to degradation, and wasn't sure about including non-degradable things in operative's core API. Maybe the transfers thing should be in the form of a plugin? Not sure. If you have time to submit a PR (even messy code is ok) that'd be really great -- I'd like to experiment a bit with it. |
Will try and send a PR in the next few days, as soon as I've had a chance to do some post-launch cleanup and consolidation. The project we launched today uses the modified version I referred to above. We're using it to triangulate and project a load of geometry onto a sphere - the end result is quite chunky, and structured cloning is slower than ideal, so the input 2d geometry and the output 3d geometry are transferred as ArrayBuffers. Our version of operative exposes a property called |
Congrats on the launch! Out of curiosity are you pooling workers/operatives for machines with > 1 core? |
How does this look? -- https://github.com/padolsey/operative/wiki/Transfers-API (this is what I'm currently implementing for a 0.4 rc. |
@padolsey - Looks good. One small note, I don't believe Transferable On Mon, Oct 6, 2014 at 11:35 PM, James Padolsey notifications@github.com
|
That's true -- but I meant that transferring Transferable objects via postMessage is a feature of postMessage... but that's all needlessly convoluted ... so I'll change the wording :D |
This is now available in |
This is awesome! Sorry I never got round to sending that PR - probably for the best, your implementation is a good bit neater than the hacks we shipped our project with :-) |
This is a slightly speculative issue but I thought it worth raising - do you have any plans to support transferable objects?
For anyone not familiar: transferable objects allow you to transfer an
ArrayBuffer
(and also aCanvasProxy
orMessagePort
, whatever they are!) to and from a web worker - rather than using the structured cloning algorithm, the reference to a transferable object is 'neutered' once it's transferred - the chunk of memory actually changes owner.I'm using operative in a project that deals with large amounts of binary data. I've implemented support for transferables in my local copy of the library, and it's blazing fast. If it's useful I can tidy up the code and share it when I get a chance (it's probably not PR-worthy yet).
This is a heavily condensed illustration of how I'm using it:
An alternative API is to specify the data and the transfer list separately (which is how it works under the hood with
postMessage
:It's fairly easy to detect support for transferables (you just try transferring an array buffer and see if the
byteLength
falls to zero - article), and falling back to structured cloning works just fine.The text was updated successfully, but these errors were encountered: