Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shared memory between Isolates using IndexedDB

I'm working with Isolates right now and wanted to know if using IndexedDB to share data between Isolates is a good way to communicate? Specifically, I want one Isolate to be able to write to it, then tell the other Isolates they may readonly it. This is data that would be considered unchanging once it is written and is fairly large. The main reason I want to do this is because I don't want to send a 6MB Map to 3 different Isolates since it is a bit intensive on the program.

like image 594
Austin Salgat Avatar asked Oct 20 '22 14:10

Austin Salgat


2 Answers

Web workers allow you to pass array buffers between workers without copying. However once you pass an array buffer to another worker the original worker looses access to its contents.

So you could try store your data structure in an array buffer to take advantage of this.

See this mdn article, and html5rocks.

So for Dart, store your data in a ByteData, and then when compiled via dartjs this should not be copied, but transferred.

Side note: Mozilla is also doing some experimentation with shared mutable access to array buffers across multiple web workers. This is to allow emscripten to compile multithreaded c code to javascript. This sort of shared access will likely take a while to get standardised and widely implemented.

like image 193
Greg Lowe Avatar answered Oct 27 '22 09:10

Greg Lowe


If you want to store the data in the IndexedDB anyway this is fine. If you do it just to optimize the communication I don't think this is an improvement over sending directly. Serialization/deserialization is usually the most CPU intensive part. Using IndexedDB additionally writes once and reads three times to/from the slow disk.

like image 22
Günter Zöchbauer Avatar answered Oct 27 '22 11:10

Günter Zöchbauer