This issue is tracking our ongoing work on making isolates more lightweight and improving communication between them. This work will mostly focus on isolates which were spawned from the same source.
As part of this work we will investigate a number of approaches, including:
We would like to implement this in several stages, here's our current progress:
SendPort.sendAndExit to allow close to 0-cost sending of messagesSubtasks for AOT enable by-default
Isolate.spawn() API have been augmented to supply Dart_InitializeParams.initialize_isolate callback with correct implementation.Subtasks for JIT
Resolver code is re-entrant by adding appropriate locks (already now BG compiler is doing method resolution while mutator can change modify the data structures)RunWithMutatorsStopped in SwitchableCall miss handler to only around patching the tuple in the pool (and remove hack in symbol table)NOTICE
This work will require substantial restructuring of the Dart VM internals and is therefore relatively risky and giving a concrete timeline is not possible - that being said we expect to make good progress on this in the coming months.
The (old) isolates will continue to be available as they were before and we will try to ensure to not regress any existing code.
What the actual improvements in terms of isolate spawning time, parallelization as well as communications will be can only really be seen once the implementation is done. That being said, we can get numbers for some features in an intermediate stage.
Thread local allocation buffers (TLABs) have been restored in df34f65d90, 5737b452b and the background compiler has been changed to allow allocating into new space in fb88c983e7.
A prototype for faster sending of mutable messages across isolates has been made in cl/92280, which might allow 2-3x faster serialization and close to O(1) deserialization time.
A prototype for transferrable byte arrays is available in cl/86640
Before we can start working on heap unification we have to change the isolate spawning functionality which currently just calls out to the embedder and assumes the embedder happens to load the exact same code into the isolate. See https://github.com/dart-lang/sdk/issues/36648.
transferable typeddata landed in https://dart-review.googlesource.com/c/sdk/+/99623
Eagerly looking for the outcome of this feature request :D
Considering you guys seem to have made a lot of progress on this already, do you have a design doc outlining the general intended outcome or usage of the new paradigm?
It is understood that lot more work is still to be done in this direction. Is it still possible to share how lightweight isolates may become? In terms of what parameters the lightweightness is aimed?
There are some references in the web that Dart isolates have a memory overhead of 2MB, which is more in the range of OS thread overhead. Is the goal of this work to make isolates lightweight like green threads? There are also references in the web that the original design goal of Dart isolates was to follow actor model - is that still the direction?
Isolates are not for lightweight concurrency as such. But for green threads or lightweight process concurrency, comparisons would be memory overheads of Kotlin’s coroutines (“a few dozen bytes”), Akka actors (~300 bytes), Pony actors (256 bytes), Erlang processes (309 words = 309x8 bytes in 64-bit architectures).
Most helpful comment
Eagerly looking for the outcome of this feature request :D
Considering you guys seem to have made a lot of progress on this already, do you have a design doc outlining the general intended outcome or usage of the new paradigm?