Skip to content
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

[dart tool] dart run <dart-file> is significantly slower than dart <dart-file> command #43969

Closed
subfuzion opened this issue Oct 28, 2020 · 3 comments
Assignees
Labels
area-dart-cli Use area-dart-cli for issues related to the 'dart' command like tool.

Comments

@subfuzion
Copy link

Running dart run <dart-file> is much slower than running dart <dart-file>. This is inconsistent with the dart tool doc and the issue was raised on reddit. It appears the dart run version is doing much more work before starting the app. See comparisons below:

example/hello.dart

void main() {
  print('hello');
}
$ time dart run example/hello.dart
hello

real    0m0.630s
user    0m0.432s
sys     0m0.134s
$ time dart example/hello.dart
hello

real    0m0.190s
user    0m0.188s
sys     0m0.073s
$ time pub run example/hello.dart
hello

real    0m0.360s
user    0m0.417s
sys     0m0.127s

Dart SDK version: 2.11.0-240.0.dev (dev) (Tue Oct 20 16:27:23 2020 -0700) on "macos_x64"

@subfuzion subfuzion changed the title [dart tool] dart run foo.dart is significantly slower than dart foo.dart command [dart tool] dart run <dart-file> is significantly slower than dart <dart-file> command Oct 29, 2020
@devoncarew devoncarew added the area-dart-cli Use area-dart-cli for issues related to the 'dart' command like tool. label Oct 29, 2020
@devoncarew
Copy link
Member

cc @bkonyi

(Ben, if you're not subscribed to area-dart-cli you might want to)

@bkonyi
Copy link
Contributor

bkonyi commented Oct 29, 2020

This isn't terribly surprising as dart foo.dart takes a different startup path than dart run foo.dart and even dart --observe foo.dart.

dart foo.dart basically acts as a fast path that skips starting the CLI isolate as the VM knows how to handle all the options without deferring to the CLI isolate and doesn't require that isolate to startup any debugging services like DDS. If dart run foo.dart is run instead, the VM sees run, realizes it's a CLI command, and then starts the CLI isolate from a kernel snapshot. Running straight from a kernel snapshot isn't particularly performant when it comes to startup time, especially compared to a pre-trained app-jit snapshot, but we chose to take the performance hit for now due to the extra complexity involved with being able to fall back from an app-jit snapshot to a kernel snapshot when incompatible flags were provided to the VM.

TL;DR: this is a known limitation due to an implementation decision that I'll try to address in the coming quarter.

@bkonyi bkonyi self-assigned this Oct 29, 2020
@subfuzion
Copy link
Author

subfuzion commented Oct 29, 2020

Thanks @bkonyi. Makes sense and aligns with observation, but we should at least make sure our docs correctly reflect this to avoid developer confusion. Currently the docs at dart: The Dart command-line tool imply the two are identical.

dart <DART_FILE> : Runs a Dart program, just like dart run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-dart-cli Use area-dart-cli for issues related to the 'dart' command like tool.
Projects
None yet
Development

No branches or pull requests

3 participants