3 ms·
No, these have very well optimized fastpaths in all engines. The method I'd expect for high-throughput communication between js and wasm would be for the wasm
by kannanvijayan 9y ago
No, these have very well optimized fastpaths in all engines.
The method I'd expect for high-throughput communication between js and wasm would be for the wasm code to build structures directly in memory and for JS to traverse those directly using the memory buffer (TypedArray, but really ArrayBuffer).
TypedObjects in ES* will let you directly build lightweight JS objects that are just pointers into an ArrayBuffer.
Edit: Updated to note the fact that I really don't know what the status of TypedObjects is currently..
- jamii 9y agoIt's hard to find out. Noone really seems to be talking about it. It is enabled in Firefox nightly, though I don't know if the API is stable yet: > var Point = new TypedObject.StructType({x:TypedObject.int32, y:TypedObject.int32}) undefined > new Point({x:1, y:2}) InlineTransparentTypedObject { x: 1, y: 2 }
- kannanvijayan 9y agoYeah it's weird. I remember hearing a lot about it a couple years back, and when SpiderMonkey implemented in Firefox it was a noticeable change, largely because we used to call one our hidden type structures "TypeObjects", and that was super confusing when there was a language construct called "TypedObjects", so we renamed our TypeObjects to "ObjectGroup". Seemed like a really nice proposal for procedural construction of typed views into ArrayBuffers, and perplexing that talk of it seems to have died down...
- JSChoi 9y agoThere is a Mozilla bug from last February [https://bugzilla.mozilla.org/show_bug.cgi?id=1336740 https://bugzilla.mozilla.org/show_bug.cgi?id=1336740] that proposes that MDN document that particular TypedObject API, since it was experimentally implemented by Firefox. Florian Scholz of Mozilla then commented: > The TypedObject proposal predates ES2015 and the yearly release model ECMAScript is on now. That said, the Firefox experimental implementation is not based on current standards work. I'm not sure how useful it is to further advertise or to document it in this case. Lars T. Hansen of Mozilla added: > IMO it's premature to document TypedObjects. I think TypedObjects are coming back, but initially to support WebAssembly's interaction with JS, and I would expect the TypedObjects' form to be slightly different from what we have now, more suited to that purpose. So we may look forward to an eventual revised TC39 proposal for TypedObject, one that explicitly considers interoperability with WebAssembly. But that will probably take a long time. Hopefully someone will write a strawman proposal/polyfill soon.
- jamii 9y agoThanks, that's really useful info :)