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

Performance regression after #8447 #9738

Closed
jchavarri opened this issue Jan 15, 2024 · 8 comments · Fixed by ocaml/opam-repository#25186
Closed

Performance regression after #8447 #9738

jchavarri opened this issue Jan 15, 2024 · 8 comments · Fixed by ocaml/opam-repository#25186

Comments

@jchavarri
Copy link
Collaborator

While testing most recent commits from main I noticed that noop builds were sustantially slower in the last weeks.

After dissecting for the past few months, I could pin down to commit 9105a43, from #8447, cc @rgrinberg @Alizter as PR author and reviewer.

The regression makes the noop build in Ahrefs case almost 2x slower:

# using commit 9105a43b719cc66aefd7c7f84816bd1a77f236c7
$ time ../dune/_build/default/bin/main.exe build @fe.all
                                             
real    0m43.125s
user    0m41.054s
sys     0m2.092s

# using commit 9c41108359ac93d369a6e78da88ffbde8b1f8ca9
$ time ../dune/_build/default/bin/main.exe build @fe.all
                                             
real    0m22.828s
user    0m21.099s
sys     0m1.760s

All other things in the measurements above are equal. I am building the dune exe using dune build bin/main.exe and calling the exe directly as shown in the time commands above.

I will investigate more tomorrow to see if I can identify which particular rules are slowing down, in case there are any other info I can provide, please lmk.

@jchavarri
Copy link
Collaborator Author

Here are some perf measurements, obtained with following commands:

perf record -F 1000 --call-graph dwarf ../dune/_build/default/bin/main.exe build @fe.all
perf script -F +pid > xxx.perf

And a few screenshots, there are quite some differences between both, they seem to be concentrated in the rule loading stage:

9c41108 9105a43
image image
image image

@rgrinberg
Copy link
Member

Simplest thing you could do to mitigate this, is to speed up the comparison of dune file ast's by including a checksum inside the dune file data structure. See Dune_engine.Dep for an example of how we do this.

@nojb
Copy link
Collaborator

nojb commented Jan 16, 2024

@rgrinberg the slowdown seems pretty consequential (100% slower in no-op builds); is the reason for the slowdown understood? was a slowdown expected as a consequence of #8447?

@rgrinberg
Copy link
Member

Somewhat of a slowdown as expected. The reason is understood. #8447 relies a lot more on the comparisons of dune files which is slow. We already rely on this comparison elsewhere so I thought it wouldn't make much of a difference.

Tbh, it's probably not a huge issue anyway. Incremental build performance for workspaces that large is pretty hopeless without the watch mode. I'm more interested in improving the watch mode to make it usable for more people, but of course I'll accept whatever optimizations people for 0 builds.

@nojb
Copy link
Collaborator

nojb commented Jan 17, 2024

For what is worth, I tested LexiFi's codebase: a noop build went from 2.8s (with Dune 3.8) to 3.6s (with a version not very far from the current main).

rgrinberg added a commit that referenced this issue Jan 18, 2024
Get rid of the slow dune file comparison in #9738

Signed-off-by: Rudi Grinberg <[email protected]>

<!-- ps-id: 6499de7c-e597-44e0-af7f-33bf7bf235ab -->
rgrinberg added a commit that referenced this issue Jan 18, 2024
Get rid of the slow dune file comparison in #9738

Signed-off-by: Rudi Grinberg <[email protected]>

<!-- ps-id: 6499de7c-e597-44e0-af7f-33bf7bf235ab -->
rgrinberg added a commit that referenced this issue Jan 18, 2024
Get rid of the slow dune file comparison in #9738

Signed-off-by: Rudi Grinberg <[email protected]>

<!-- ps-id: 6499de7c-e597-44e0-af7f-33bf7bf235ab -->
rgrinberg added a commit that referenced this issue Jan 18, 2024
Get rid of the slow dune file comparison in #9738

Signed-off-by: Rudi Grinberg <[email protected]>

<!-- ps-id: 6499de7c-e597-44e0-af7f-33bf7bf235ab -->
rgrinberg added a commit that referenced this issue Jan 18, 2024
Get rid of the slow dune file comparison in #9738

Signed-off-by: Rudi Grinberg <[email protected]>

<!-- ps-id: 6499de7c-e597-44e0-af7f-33bf7bf235ab -->
rgrinberg added a commit that referenced this issue Jan 18, 2024
Get rid of the slow dune file comparison in #9738

Signed-off-by: Rudi Grinberg <[email protected]>
@jchavarri
Copy link
Collaborator Author

Fixed in #9769.

@Khady
Copy link
Contributor

Khady commented Jan 22, 2024

Tbh, it's probably not a huge issue anyway. Incremental build performance for workspaces that large is pretty hopeless without the watch mode. I'm more interested in improving the watch mode to make it usable for more people, but of course I'll accept whatever optimizations people for 0 builds.

It is a huge issue. Watch mode just doesn’t cut it for now. There are multiple things that dune do not handle and require staged compilation for example. And the lock just blocks too many operations that require to stop the watch mode. Such a slow down also makes watch mode much more troublesome to use because it takes longer to start.

@rgrinberg
Copy link
Member

All of those facts point to improving the watch mode. We've fixed the regression but a 0 build is still 20 seconds and optimizing it beyond that would require a lot of work. On the other hand, improving the watch mode is fairly straightforward.

emillon pushed a commit to emillon/dune that referenced this issue Feb 5, 2024
Get rid of the slow dune file comparison in ocaml#9738

Signed-off-by: Rudi Grinberg <[email protected]>
emillon added a commit that referenced this issue Feb 5, 2024
* refactor: rename [Dune_load.conf] to [Dune_load.t] (#9766)

Signed-off-by: Rudi Grinberg <[email protected]>

* refactor: Make [Dune_load.t] abstract (#9767)

Signed-off-by: Rudi Grinberg <[email protected]>

* refactor: move [Dune_load.Dune_files.in_dir] (#9768)

It doesn't need to be in the [Dune_files] submodule

Signed-off-by: Rudi Grinberg <[email protected]>

* fix: performance regression from #8447 (#9769)

Get rid of the slow dune file comparison in #9738

Signed-off-by: Rudi Grinberg <[email protected]>

---------

Signed-off-by: Rudi Grinberg <[email protected]>
Co-authored-by: Rudi Grinberg <[email protected]>
emillon added a commit to emillon/opam-repository that referenced this issue Feb 5, 2024
CHANGES:

- Fix performance regression for incremental builds (ocaml/dune#9769, fixes ocaml/dune#9738,
  @rgrinberg)

- Fix `dune ocaml top-module` to correctly handle absolute paths. (ocaml/dune#8249, fixes
  ocaml/dune#7370, @Alizter)

- subst: ignore broken symlinks when looking at source files (ocaml/dune#9810, fixes
  ocaml/dune#9593, @emillon)

- subst: do not fail on 32-bit systems when large files are encountered. Just
  log a warning in this case. (ocaml/dune#9811, fixes ocaml/dune#9538, @emillon)

- boot: sort directory entries in readdir. This makes the dune binary
  reproducible in terms of filesystem order. (ocaml/dune#9861, fixes ocaml/dune#9794, @emillon)
nberth pushed a commit to nberth/opam-repository that referenced this issue Jun 18, 2024
CHANGES:

- Fix performance regression for incremental builds (ocaml/dune#9769, fixes ocaml/dune#9738,
  @rgrinberg)

- Fix `dune ocaml top-module` to correctly handle absolute paths. (ocaml/dune#8249, fixes
  ocaml/dune#7370, @Alizter)

- subst: ignore broken symlinks when looking at source files (ocaml/dune#9810, fixes
  ocaml/dune#9593, @emillon)

- subst: do not fail on 32-bit systems when large files are encountered. Just
  log a warning in this case. (ocaml/dune#9811, fixes ocaml/dune#9538, @emillon)

- boot: sort directory entries in readdir. This makes the dune binary
  reproducible in terms of filesystem order. (ocaml/dune#9861, fixes ocaml/dune#9794, @emillon)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants