Skip to content

Isolate.spawnUri seems to be slower than starting a new VM in another process (on macos) #42183

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

Open
sigurdm opened this issue Jun 4, 2020 · 1 comment
Assignees
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends.

Comments

@sigurdm
Copy link
Contributor

sigurdm commented Jun 4, 2020

This came up here dart-lang/pub#2492
@mkustermann @a-siva

I made a small reproduction:

// bin/spawn.dart
import 'dart:io';
import 'dart:isolate';

main(List<String> args) {
  if (args.isNotEmpty && args.first == 'isolate') {
    Isolate.spawnUri(Uri.parse('hello.dart'), [], null);
  } else {
    Process.runSync(Platform.resolvedExecutable,
        [Platform.script.resolve('hello.dart').toString()]);
  }
}
// bin/hello.dart
main() {
  print('hello world');
}
> dart --version
Dart VM version: 2.8.3 (stable) (Tue May 26 18:39:38 2020 +0200) on "macos_x64"
> dart --snapshot=bin/spawn.dart.snapshot ./bin/spawn.dart 
> time  dart bin/spawn.dart.snapshot isolate
hello world

real    0m0.642s
user    0m0.697s
sys     0m0.113s
> time  dart bin/spawn.dart.snapshot 

real    0m0.288s
user    0m0.335s
sys     0m0.092s

I would have expected using an isolate would save some time by sharing some amount of resources, or at least be on par with starting a new process.

Using an isolate is slightly faster if I don't snapshot the spawning script.

> time  dart bin/spawn.dart 

real    0m0.964s
user    0m1.027s
sys     0m0.197s
> time  dart bin/spawn.dart isolate
hello world

real    0m0.882s
user    0m0.980s
sys     0m0.163s

This was measured on macos.

On my linux machine using an isolate seems to be faster (note here I use a dev-version, just what I had in my path...):

> dart --version
Dart VM version: 2.9.0-5.0.dev (dev) (Thu Apr 30 13:02:02 2020 +0200) on "linux_x64"
> dart --snapshot=bin/spawn.dart.snapshot ./bin/spawn.dart
> /usr/bin/time dart bin/spawn.dart.snapshot isolate
hello world
0.25user 0.15system 0:00.28elapsed 141%CPU (0avgtext+0avgdata 127504maxresident)k
0inputs+0outputs (0major+22664minor)pagefaults 0swaps
> /usr/bin/time dart bin/spawn.dart.snapshot 
0.37user 0.15system 0:00.34elapsed 153%CPU (0avgtext+0avgdata 122164maxresident)k
0inputs+0outputs (0major+27981minor)pagefaults 0swaps
@a-siva
Copy link
Contributor

a-siva commented Jun 4, 2020

Thanks for the simple reproduction case, will take a look.

@mkustermann mkustermann added the area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. label Jun 4, 2020
@a-siva a-siva self-assigned this Jun 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends.
Projects
None yet
Development

No branches or pull requests

3 participants