WebWorkers, Isolates, and Transferable Objects support status

129 views
Skip to first unread message

Alexey Knyazev

unread,
Nov 21, 2016, 7:16:53 PM11/21/16
to Dart Misc
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):


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

Günter Zöchbauer

unread,
Nov 22, 2016, 7:00:15 AM11/22/16
to Dart Misc
I guess this will be tackled when the migration to DDC is done.
Sounds like a lot of Dartium dependencies 

Filipe Morgado

unread,
Nov 22, 2016, 7:22:36 AM11/22/16
to Dart Misc
On Tuesday, 22 November 2016 12:00:15 UTC, Günter Zöchbauer wrote:
I guess this will be tackled when the migration to DDC is done.
Sounds like a lot of Dartium dependencies 

It should be noted that Dart is a general-purpose programming language, not web-only.
DDC alone cannot "tackle" this problem.

Isolates should work the same way on all targets.
Personally, I wouldn't mind a performance penalty on the web for more power on other targets (but I know that's just me).

Oh, and Transferables would be quite handy both on the server and mobile.

Günter Zöchbauer

unread,
Nov 22, 2016, 8:02:40 AM11/22/16
to Dart Misc


On Tuesday, November 22, 2016 at 1:22:36 PM UTC+1, Filipe Morgado wrote:
On Tuesday, 22 November 2016 12:00:15 UTC, Günter Zöchbauer wrote:
I guess this will be tackled when the migration to DDC is done.
Sounds like a lot of Dartium dependencies 

It should be noted that Dart is a general-purpose programming language, not web-only.
DDC alone cannot "tackle" this problem.

Isolates should work the same way on all targets.

When Dartium is discontinued as a target the scenario might be much easier to be solved.
I didn't say it should **only** work with DDC. 
DDC is mainly a development tool, therefore DDC only is similar to "not at all" (except for the use cases where DDC is used to reused JS generated from Dart in JS projects).
Reply all
Reply to author
Forward
0 new messages