data sharing between NaCL and javascript?

554 views
Skip to first unread message

Jim

unread,
Aug 5, 2012, 11:55:51 PM8/5/12
to native-cli...@googlegroups.com
We have some pretty big data (binary) which is loaded into NaCL and needed to be accessed frequently in javascript.
As I know, in the earlier versions of NaCL sdk, javascript code can invokes NaCL functions directly, while in later versions, only message posting can be used to communicate between NaCL and javascript.
Even though I can understand that the data sharing between different processes is nontrivial, the message mechanism is very limited and inefficient in exchanging big data.
Can anyone shed more lights on the future of NaCL development?
Thanks
Jim

Erik Kay

unread,
Aug 6, 2012, 12:02:24 PM8/6/12
to native-cli...@googlegroups.com
Hi Jim,

There are a few options for sharing large data between NaCl and JS.  The first is that you can store the data as a file and share a blob URL across processes.  This is great for large immutable data.

Another option that's coming but isn't available yet is support for transferable data in postMessage.  We support it to web workers today, but not yet with NaCl.  It's on our to do list, but likely won't come until late this year.

Erik




Jim

--
You received this message because you are subscribed to the Google Groups "Native-Client-Discuss" group.
To view this discussion on the web visit https://groups.google.com/d/msg/native-client-discuss/-/xdXbAKoHRfoJ.
To post to this group, send email to native-cli...@googlegroups.com.
To unsubscribe from this group, send email to native-client-di...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/native-client-discuss?hl=en.

David Michael

unread,
Aug 6, 2012, 2:00:22 PM8/6/12
to native-cli...@googlegroups.com
On Mon, Aug 6, 2012 at 10:02 AM, Erik Kay <eri...@google.com> wrote:
Hi Jim,

There are a few options for sharing large data between NaCl and JS.  The first is that you can store the data as a file and share a blob URL across processes.  This is great for large immutable data.


Another option that's coming but isn't available yet is support for transferable data in postMessage.  We support it to web workers today, but not yet with NaCl.  It's on our to do list, but likely won't come until late this year.
We provide support for ArrayBuffer in postMessage today, although the data do get copied currently. It's harder to support "transfer" for ArrayBuffer in NaCl since the transfer crosses a process boundary; we'll get there eventually. But it might be worth trying postMessage/ArrayBuffer anyway if it looks more convenient than Blob for you; the performance should be good enough for a lot of uses. You can see the "File Histogram" example for a quick example of sending binary data from JS to NaCl (the other direction works fine, too).

Jim

unread,
Aug 10, 2012, 3:21:47 AM8/10/12
to native-cli...@googlegroups.com
Thanks Erik and David for quick response. It seems the blob url may be better since at least the javascript part do not need lots of memory to hold the big data (or keeping transferring multiple times).
Reply all
Reply to author
Forward
0 new messages