Alexey Knyazev
2016-11-22 00:16:53 UTC
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:
- MessagePort.postMessage
<https://api.dartlang.org/stable/1.20.1/dart-html/MessagePort/postMessage.html>
- Window.postMessage
<https://api.dartlang.org/stable/1.20.1/dart-html/Window/postMessage.html>
- Worker.postMessage
<https://api.dartlang.org/stable/1.20.1/dart-html/Worker/postMessage.html>
All those functions should take List<Transferable
<https://developer.mozilla.org/en-US/docs/Web/API/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):
- Client.postMessage
<https://api.dartlang.org/stable/1.20.1/dart-html/Client/postMessage.html>
- CompositorWorker.postMessage
<https://api.dartlang.org/stable/1.20.1/dart-html/CompositorWorker/postMessage.html>
- CompositorWorkerGlobalScope.postMessage
<https://api.dartlang.org/stable/1.20.1/dart-html/CompositorWorkerGlobalScope/postMessage.html>
- CrossOriginServiceWorkerClient.postMessage
<https://api.dartlang.org/stable/1.20.1/dart-html/CrossOriginServiceWorkerClient/postMessage.html>
- DedicatedWorkerGlobalScope.postMessage
<https://api.dartlang.org/stable/1.20.1/dart-html/DedicatedWorkerGlobalScope/postMessage.html>
- ServicePort.postMessage
<https://api.dartlang.org/stable/1.20.1/dart-html/ServicePort/postMessage.html>
Here's an example of both cloning and transferring ByteBuffer to JS-based
Worker and back:
https://dartpad.dartlang.org/75b696ad9c79cf01b8b8bc3a87c262e2
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
<https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm#Supported_types>
;
- 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
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:
- MessagePort.postMessage
<https://api.dartlang.org/stable/1.20.1/dart-html/MessagePort/postMessage.html>
- Window.postMessage
<https://api.dartlang.org/stable/1.20.1/dart-html/Window/postMessage.html>
- Worker.postMessage
<https://api.dartlang.org/stable/1.20.1/dart-html/Worker/postMessage.html>
All those functions should take List<Transferable
<https://developer.mozilla.org/en-US/docs/Web/API/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):
- Client.postMessage
<https://api.dartlang.org/stable/1.20.1/dart-html/Client/postMessage.html>
- CompositorWorker.postMessage
<https://api.dartlang.org/stable/1.20.1/dart-html/CompositorWorker/postMessage.html>
- CompositorWorkerGlobalScope.postMessage
<https://api.dartlang.org/stable/1.20.1/dart-html/CompositorWorkerGlobalScope/postMessage.html>
- CrossOriginServiceWorkerClient.postMessage
<https://api.dartlang.org/stable/1.20.1/dart-html/CrossOriginServiceWorkerClient/postMessage.html>
- DedicatedWorkerGlobalScope.postMessage
<https://api.dartlang.org/stable/1.20.1/dart-html/DedicatedWorkerGlobalScope/postMessage.html>
- ServicePort.postMessage
<https://api.dartlang.org/stable/1.20.1/dart-html/ServicePort/postMessage.html>
Here's an example of both cloning and transferring ByteBuffer to JS-based
Worker and back:
https://dartpad.dartlang.org/75b696ad9c79cf01b8b8bc3a87c262e2
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
<https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm#Supported_types>
;
- 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
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.