Isolate groups in Dart (introduced in version 2.15) allow isolates to share code and some memory structures, significantly increasing the efficiency of communication. Based on my investigation of the Dart SDK's runtime implementation and documentation, here is a summary of what is efficient to send:
When isolates are in the same isolate group (which is the default for isolates created via Isolate.spawn()), the following objects are shared by reference rather than copied:
- All Strings: In the Dart VM, all strings are considered "deeply immutable" and are shared by reference.
- Primitive Types:
bool,int,double, andNull. - Constants: Any object created with the
constkeyword. - Special System Objects:
SendPort,Capability,RegExp,StackTrace, andType. - Deeply Immutable Instances: Objects of classes annotated with
@pragma('vm:deeply-immutable'). - Stateless Closures: Closures that do not capture any mutable