Description
Currently, pub run
invocations always invoke the pub
executable. The executable is necessary to fully handle all the potential complexities of locating, configuring, and potentially re-snapshotting the executable, but it also involves a substantial performance hit, some of which comes unavoidably just from loading pub's code.
The best way to address this is to avoid invoking pub at all. It should be possible for the script that invokes pub to cheaply detect a pub run
invocation that doesn't need special configuration, and to directly invoke the Dart executable. In particular, it should check:
- That the
run
command is being invoked without any global arguments. - That the only arguments to
run
are the executable name and, optionally,--checked
. - That the executable name is a single Dart identifier or two Dart identifiers separated by a colon.
- That the corresponding executable snapshot exists in
.pub
(for example, forpub run foo:bar
, the snapshot will be in.pub/bin/foo/bar.dart.snapshot
). - That
pubspec.yaml
,pubspec.lock
, and.packages
files all exist. - That the snapshot has a more recent modification time than
pubspec.yaml
. - That the snapshot is compatible with the current
dart
executable (blocked on Add a facility to test whether a snapshot is up-to-date without running it #20802).
If all of these are true, the script should exec
the snapshot (or whatever the equivalent of exec
is on Windows).
This is blocked on:
- Add a facility to test whether a snapshot is up-to-date without running it #20802, to be able to check if the snapshot is up-to-date.
- "pub run" should spawn an isolate rather than starting a subprocess pub#1204, because otherwise various behavioral details such as signal handling will differ depending on whether the executable was fast-tracked or not.
I'm filing this in the SDK repo because it involves changing the POSIX and Windows pub wrapper scripts, which live here. Also, unfortunately, I don't have the shell expertise (especially with the Windows shell) to implement this myself. That said, I'm happy to work with someone who does have that expertise to get this implemented.