Language: Efficient communication of data between isolates

Created on 4 Dec 2018  Â·  7Comments  Â·  Source: dart-lang/language

A common pattern in flutter apps is to offload computationally intensive work (e.g. json decoding) to a separate isolate to avoid blocking the main UI thread. This breaks down when the isolate needs to return large amounts of data to the UI thread, since just the time to transfer the data back to the main isolate can block the main isolate for too long.

request

All 7 comments

cc @mraleph @jacob314

This would also be a huge help to the IDE too. Often they're written to take advantage of parallelism, so they can respond quickly to some requests (e.g. autocomplete) while taking more time to respond to others.

(C#'s IDE for example is designed to take advantage of .NET's Task Parallel Library)

/cc @aam who is investigating transferrables.

I think that the dart-lang team should focus on providing a real threads support, with shared memory, for Dart rather than trying to improve the communication between Isolates which would just be a sticking-plaster solution (with many limitations like the immutability of shared objects between Isolates). Isolates should simply be used for isolated tasks, as their name suggests, requiring little or no data transfer between processes. For the rest Dart should offer the possibility to use real threads, like any modern programming language worthy of the name

I send message to the other isolate from the main isolate takes almost 8ms, it takes too long time of port communication.
2019-12-12 14:38:03.707 7699-7718/com.example.flutter_app I/flutter: >>>>sendMessage action: EXECUTE_JS 2019-12-12 14:38:03.717 7699-7730/com.example.flutter_app I/flutter: receive message from main.......

Is anybody working on this issue?

--

I've provided a rudimentary benchmark to measure skipped frames due to inefficient communication between isolates in https://github.com/dart-lang/sdk/issues/40653

This is the result of a single run (json encoding and decoding):

13985982 bytes, please wait ~10 seconds.
 • Isolate Decode
   - Took          : 196
   - SkippedFrames : 152     (Frame 241 to 393)

 • Isolate Encode
   - Took          : 187
   - SkippedFrames : 6     (Frame 482 to 488)

 • Decode
   - Took          : 47
   - SkippedFrames : 47     (Frame 488 to 535)

 • Encode
   - Took          : 29
   - SkippedFrames : 30     (Frame 535 to 565)

This shows that it's impossible to have a smooth UI when a big json string has to be decoded and consumed entirely by the main isolate.

We are actively working on implementing improvements to the concurrency story in the VM. The design space is vast, so we are focused mainly on implementing underlying infrastructure. One of the first approaches we are going to try, once the infrastructure is fully in place, is "send-and-exit" approach (tracked by https://github.com/dart-lang/sdk/issues/37835).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

moneer-muntazah picture moneer-muntazah  Â·  3Comments

kevmoo picture kevmoo  Â·  3Comments

wytesk133 picture wytesk133  Â·  4Comments

leafpetersen picture leafpetersen  Â·  3Comments

har79 picture har79  Â·  5Comments