-
Notifications
You must be signed in to change notification settings - Fork 207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Efficient communication of data between isolates #124
Comments
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. |
Is anybody working on this issue? -- I've provided a rudimentary benchmark to measure skipped frames due to inefficient communication between isolates in dart-lang/sdk#40653 This is the result of a single run (json encoding and decoding):
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 dart-lang/sdk#37835). |
The core of this issue seems to be
This is now addressed with a newly exposed Isolate.exit() API (was recently added as part of dart-lang/sdk#47164) that can be used to hand ownership of large amounts of data to another isolate without making the receiver having a O(n) cost. There's a few follow-up items in dart-lang/sdk#37835 though the main functionality is implemented now. Even when not using What does remain is that isolates coordinate on garbage collections - so certain pauses due to GC are shared across isolates. Though even single-isolate scenarios pay this pause cost. Closing this issue since most planned work has been implemented as part of dart-lang/sdk#36097 |
Can't help but ask. What prevents from adding support for (almost) 0-cost transfer between isolates without copying of typed data and Lists, Maps, Sets that contain only primitive types and are not referenced by anything?
|
For 0-cost / sharing of objects, one has to choose between a) mutable b) immutable (and maybe c) transfer). So far we always avoided the mutable option because it would allow one isolate to see side-effects (mutations of objects of any kinds) from other isolates. This is unexpected for the programmer and usually one needs to provide synchronization/locking primitives to allow a programmer to work safely in such an environment. So we have chosen the immutable option for now. So transitively immutable objects (e.g. any constant, non-constant strings) are shared. For allowing other data structures (e.g. typed lists as you suggest) to be immutable one has to do more checking at runtime or have type-system guarantees (as you suggest with The runtime option we have so far avoided due to cost in performance and code-size. The language option we have not explored yet: It is a long process to make language changes and one would want to make it generally applicable (ideally also for composites). |
@mkustermann what about doing it in a Javascript-like way at least for typed lists?
The only drawback of this approach that I currently see is that this allows for the existence of typed lists which have offsets greater than the underlying buffer's length. But perhaps the existing range checks will deal with this anyway? |
For typed list specifically One can have multiple views on top of one backing store. So transferring one view would transfer the backing store, rendering all other views unusable. This is suboptimal - as it can lead to very obscure bugs in programs. The mechanism of transferring will effectively make the typed list have length 0 and error on read/write access. The fact that the length can change means our optimizing compiler can no longer do certain optimizations, making byte access slower. So we would pay for better inter-isolate typed data support with normal byte access speed. This is a hard sell - but maybe we'll push for it in the future. @MadOPcode In the meantime I can offer you an (unsafe) escape hatch: You can use Please consider opening a new issue if you have other requests, as this issue is specific to blocking UI thread when receiving data from helper isolates, which we have fixed. |
@mkustermann What if instead of changing the length, the
I have a proposal for a language-level solution that relies on being able to perform a recursive move/transfer of the underlying data in collections - #3298 - and am looking to get some expert/team feedback on it
While |
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.
The text was updated successfully, but these errors were encountered: