sdk
sdk copied to clipboard
remove eager startup of service and kernel isolates
It seems wasteful (both in terms of start up time and memory usage) to eagerly start service and kernel isolates especially when running from a snapshot.
In Dart 1 Service handled source loading and this is still reflected in the API (e.g. there is a method called Dart_ServiceWaitForLoadPort). However a lot of this code is now just an artifact of Dart 1 times, because actual code loading is handled by CFE.
It feels like there is a huge potential for cleaning this up considerably.
/cc @a-siva @rmacnak-google
As a data point for this, the memory footprint of the flutter tool would be reduced by ~40MB (typically 5-25%) with the kernel service snapshot loaded lazily and the isolate started lazily.
https://dart-review.googlesource.com/c/sdk/+/121923 accounts for lazy starting of kernel isolate.
'flutter doctor' maxRss: before: 242 MB after: 200 MB
Thanks!
Let us start with the work on restructuring how the service isolate is started first (move it out of the VM initialization into the embedder)
Here is something to consider related to this: I’ve tried to land a change to fix https://github.com/dart-lang/sdk/issues/60256 a few times. The that fix I’ve been trying to land makes the VM shut down when either the VM Service or DDS fail to start during VM initialization. Attempting to land it has revealed programs that get broken by my fix because with a "pre-fix" VM, they request for the VM Service to be started, but always encounter failures to start the VM Service, but since they never actually make any calls to the VM Service, failing to start the VM Service doesn't affect them. If the service isolate is changed to start up lazily, then the VM Service won't be started at all in those programs, and they won't be broken by my fix.