Skip to content

Conversation

@Alizter
Copy link
Collaborator

@Alizter Alizter commented Dec 5, 2025

This table is only created and used twice. We add an Id.t field so that
it can easily be compared later when it's values are memoized in the
of_ctx call.

The old hash and equality functions were expensive an unnecessary.

Before:

[ocaml-cohttp]$ hyperfine "dune build"
Benchmark 1: dune build
  Time (mean ± σ):      1.722 s ±  0.043 s    [User: 1.438 s, System: 0.281 s]
  Range (min … max):    1.664 s …  1.814 s    10 runs

After:

[ocaml-cohttp]$ hyperfine "dune build"
Benchmark 1: dune build
  Time (mean ± σ):      1.064 s ±  0.020 s    [User: 0.790 s, System: 0.274 s]
  Range (min … max):    1.032 s …  1.090 s    10 runs

@Alizter Alizter force-pushed the push-rmmwsrozxnzs branch 4 times, most recently from 5edd17c to 274a7cd Compare December 9, 2025 09:29
@Alizter Alizter changed the title perf: memoize Pkg_rules.DB values perf: don't recreate Pkg_rules.DB values Dec 9, 2025
@Alizter Alizter force-pushed the push-rmmwsrozxnzs branch 2 times, most recently from 2b8bc92 to 31e5bb2 Compare December 9, 2025 12:14
@Alizter Alizter marked this pull request as ready for review December 9, 2025 12:14
@Alizter Alizter requested a review from rgrinberg December 9, 2025 13:26
@Alizter Alizter marked this pull request as draft December 9, 2025 13:33
@Alizter Alizter changed the title perf: don't recreate Pkg_rules.DB values pkg: don't recreate Pkg_rules.DB values Dec 10, 2025
@Alizter Alizter requested a review from rgrinberg December 10, 2025 10:15
@Alizter Alizter marked this pull request as ready for review December 10, 2025 10:15
Copy link
Member

@rgrinberg rgrinberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous code was needlessly convoluted so your attempt at memoization lost sharing. I refactored things to be clearer and gained back the sharing.

Alizter and others added 5 commits December 16, 2025 10:40
This table is only created and used twice. We add an Id.t field so that
it can easily be compared later when it's values are memoized in the
of_ctx call.

The old hash and equality functions were expensive an unnecessary.

We also memoize the of_dev_tool caller

Before:
```
[ocaml-cohttp]$ hyperfine "dune build"
Benchmark 1: dune build
  Time (mean ± σ):      1.851 s ±  0.039 s    [User: 1.561 s, System: 0.283 s]
  Range (min … max):    1.814 s …  1.943 s    10 runs
```

After:
```
[ocaml-cohttp]$ hyperfine "dune build"
Benchmark 1: dune build
  Time (mean ± σ):      1.086 s ±  0.016 s    [User: 0.803 s, System: 0.279 s]
  Range (min … max):    1.052 s …  1.108 s    10 runs
```

Signed-off-by: Ali Caglayan <[email protected]>
Signed-off-by: Rudi Grinberg <[email protected]>
Signed-off-by: Ali Caglayan <[email protected]>
The DB is already memoized

Signed-off-by: Rudi Grinberg <[email protected]>
Signed-off-by: Ali Caglayan <[email protected]>
@Alizter Alizter merged commit 894ece7 into ocaml:main Dec 16, 2025
30 checks passed
@Alizter Alizter deleted the push-rmmwsrozxnzs branch December 16, 2025 11:20
@shonfeder
Copy link
Member

shonfeder commented Dec 18, 2025

Contributes to #12693

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pkg: Performance regression in no-op builds when using dune package management

3 participants