Hi everyone,
While developing WebGL-related stuff, which involves lots of heavy computations, I was able to evaluate current (as of 1.20.1) status of Isolate/WebWorker support in Dart.
Running Native JS WebWorkers from Dart
It's possible to run native JS WebWorker from Dart code, but several dart:html bindings aren't correct:
All those functions should take List<
Transferable> instead of List<MessagePort>. There're several open issues on GitHub about that.
Same applies to other similar functions (ServiceWorker API and others, btw some of them are obsolete):
Here's an example of both cloning and transferring ByteBuffer to JS-based Worker and back:
Please, pay attention that buffer.lengthInBytes value remains intact after buffer cloning, but changes to zero after transferring. It's correct.
In Dartium, buffer's length value remains untouched in all cases (likely a bug).
Running dart2js-compiled WebWorker from JS
No success (at least for me). Calling Worker.postMessage from JS-based host results in exception in isolate_helper.dart.
Moreover, such scheme isn't very useful, since each compiled dart file include full dart runtime.
Dart Isolates
Usually work as expected, four issues here:
- Isolates-based ByteBuffer cloning round-trip is 10-20% slower, than Dart host with JS Worker;
- there's no way to "transfer" objects - only cloning available;
- Isolates don't support sending RegExp, Blob, File, FileList, and ImageData objects, while WebWorkers support them;
- no Isolates support in Dartium.
Most of the aforementioned issues are already on GitHub (some for several years), so, is there any "roadmap" on Dart's threading/concurrency support?
Regards,
Alexey Knyazev