-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
Intended change
We intend to enable isolate group sdk/issues/36097 support in the VM by-default.
This will make isolates spawned via Isolate.spawn
run inside the same Isolate Group and therefore operate on the same heap, allowing sharing of various kinds of objects and allowing better communication.
Intended change in behavior:
The intention is to
- make the per-isolate base memory overhead smaller (10x less RAM)
- make isolates faster to spawn (10x faster spawn latency)
- make isolates communicate faster (8x faster round-trip communication)
- make receiver isolate of messages mostly non-blocking (removes O(n) receiver cost)
- allow more rich communication between isolates (see sdk/issues/46623)
- allow sharing of objects (program structure, JITed code, constants as well as any
String
objects - in the future possibly also user-defined data structures) - fix long-standing bugs that happen if isolates are used with the (currently non-atomic) hot-reload (e.g. flutter/issues/72195)
- allow flutter to smoothly use multiple engines flutter.dev/docs/development/add-to-app/multiple-flutters
The justification/rationale for making the change
Get the improvements mentioned above to users. Enabling more data sharing of objects across isolates in the future.
The expected impact of this change
There are no functional differences. There will be changes in performance characteristics. Those changes will almost exclusively be positive.
The thread pool onto which all lightweight isolates are multiplexed onto is limited (around 10 atm), in order to ensure all threads executing on different cores have a big enough TLAB (thread local allocation buffer - a free chunk of memory from new space) to ensure fast bump allocation.
This means isolates will collaborate on garbage collections (and some other events like lazy JIT compilations, ...). As a consequence blocking GC operations (such as new space collections) will affect all isolates. The worst case pause time due to new space collections is unchanged, however heavily allocating isolates can impact other isolates.
In the common case where generational hypothesis holds (most objects die young) those collections continue being fast. Furthermore for Flutter specifically, any idle time on the UI thread is used to perform GCs, thereby also avoiding too long pause due to new space GCs. (The old space is mainly collected via concurrent marking & sweeping, thereby not stopping mutators)
The only existing use case that could be negatively impacted is existing apps for which many isolates are executing in parallel on many cores (e.g. big server applications).
3 important Dart customers (including flutter) have been opt'ing into this already for a longer period of time in AOT mode. So far we have only heard positive feedback from them (especially memory footprint reductions).
We expect the only use case that might be actually affected by this change is e.g. server customers that use isolates on many threads at the same time.
Clear steps for mitigating the change
For customers that use isolates on many threads at the same time (such running on large servers), the possible workaround is to use Isolate.spawnUri()
on the same application - this will cause the VM to use an independent Isolate Group which gives the old behavior. Though communication is then restricted to json-like types.
(see also go/ig-by-default)