dune icon indicating copy to clipboard operation
dune copied to clipboard

`dune exec --no-build` is slow

Open Khady opened this issue 1 year ago • 2 comments

Expected Behavior

dune exec --no-build or dune exec when there's nothing to build should be almost as fast as launched the binary manually

Actual Behavior

Even with --no-build and a path to the binary (no need to look up for a name), dune can be 40 times slower than just launching the bin by hand

$ time dune exec ./bin/main.exe --no-build -- --version

real	0m0.655s
user	0m0.474s
sys	0m0.170s
$ time _build/default/bin/main.exe --version

real	0m0.015s
user	0m0.007s
sys	0m0.007s

The cost seems to grow higher as the binary and project gets bigger. strace shows A LOT of activity.

Reproduction

Can't open source the specific case, but any open source project can highlight this behavior

git clone https://github.com/ahrefs/atd.git
cd atd
# setup ocam libs
time dune exec --no-build atdgen/bin/ag_main.exe -- -version
time _build/default/atdgen/bin/ag_main.exe -version

Specifications

  • Version of dune (output of dune --version): 3.15
  • Version of ocaml (output of ocamlc --version): 4.14.0
  • Operating system (distribution and version): debian bullseye

Khady avatar May 10 '24 03:05 Khady

I don't know if there's much we can do. We need to load the rules in a directory to see if the executable exists. That's probably where the overhead comes from.

rgrinberg avatar May 11 '24 17:05 rgrinberg

Couldn’t we have some shortcuts, such as checking the presence of the binary in _build before to load all the rules?

Khady avatar May 11 '24 23:05 Khady

It wouldn't be a valid optimization. The rules can change between runs and the stale artifact would remain.

rgrinberg avatar May 12 '24 15:05 rgrinberg

Which would happen with --no-build anyway?

Khady avatar May 12 '24 23:05 Khady

It would not. Re-loading the rules will clear stale artifacts.

rgrinberg avatar May 12 '24 23:05 rgrinberg

I'm going to close as this is just a general performance issue of rule loading and nothing specific to dune exec.

rgrinberg avatar Jun 13 '24 21:06 rgrinberg