Skip to content

pkg: enable and version the rev_store cache - #14494

Merged
Alizter merged 1 commit into
ocaml:mainfrom
Alizter:pkg-rev-store-cache-version
May 20, 2026
Merged

Alizter merged 1 commit into
ocaml:mainfrom
Alizter:pkg-rev-store-cache-version

Conversation

@Alizter

@Alizter Alizter commented May 11, 2026 •

Copy link
Copy Markdown
Collaborator

The lmdb-backed revision store cache is now enabled by default on 64-bit
platforms (32-bit remains opted out because the 5GB map size doesn't fit
in virtual address space, and on Windows it is disabled until we can
determine it's performance impact).

The on-disk layout is now versioned: caches live under
$DUNE_CACHE_ROOT/rev_store/<version>/, with the version bumped by hand
whenever the bytes we write change shape.

The ls-tree map's value switches from a Marshal-encoded
File.Set.t * Commit.Set.t to the raw git ls-tree -z subprocess output.
This removes the previous dependency on the OCaml compiler used to build
dune, since Marshal's binary format is sensitive to runtime layout.

@Alizter Alizter added the package management Dune's package management — `(pkg)` stanza, lockdirs, `dune pkg` commands label May 11, 2026
@Alizter Alizter self-assigned this May 11, 2026
@Alizter
Alizter marked this pull request as ready for review May 11, 2026 11:20
@Alizter
Alizter requested a review from rgrinberg May 11, 2026 11:20
@Alizter
Alizter marked this pull request as draft May 12, 2026 00:44
@Alizter

This comment was marked as outdated.

@Alizter
Alizter force-pushed the pkg-rev-store-cache-version branch from 6b6101b to 719ded8 Compare May 12, 2026 14:21
@Alizter
Alizter marked this pull request as ready for review May 12, 2026 14:22
Comment thread src/dune_pkg/rev_store.ml Resolved
The lmdb-backed revision store cache is now enabled by default on 64-bit
platforms (32-bit remains opted out because the 5GB map size doesn't fit
in virtual address space).

The on-disk layout is now versioned: caches live under
$DUNE_CACHE_ROOT/rev_store/<version>/, with the version bumped by hand
whenever the bytes we write change shape.

The ls-tree map's value switches from a Marshal-encoded
File.Set.t * Commit.Set.t to the raw git ls-tree -z subprocess output.
This removes the previous dependency on the OCaml compiler used to build
dune, since Marshal's binary format is sensitive to runtime layout.

Fixes ocaml#12637.

Signed-off-by: Ali Caglayan <[email protected]>
@Alizter
Alizter force-pushed the pkg-rev-store-cache-version branch from 719ded8 to 4a54265 Compare May 20, 2026 15:46
@Alizter

Alizter commented May 20, 2026 •

Copy link
Copy Markdown
Collaborator Author

Some bench results on locking some repositories:

Project Packages cache=disabled cache=enabled Speedup
re 44 1.912 s ± 0.576 0.615 s ± 0.208 3.11x
cohttp 210 3.757 s ± 0.973 1.039 s ± 0.365 3.62x
jsoo 72 1.786 s ± 0.614 0.545 s ± 0.207 3.27x
lsp 71 1.712 s ± 0.517 0.596 s ± 0.177 2.87x
opam 9 1.002 s ± 0.362 0.249 s ± 0.063 4.02x
irmin 194 3.723 s ± 0.804 1.060 s ± 0.368 3.51x
mirage 39 1.635 s ± 0.561 0.347 s ± 0.013 4.71x
eio 50 1.532 s ± 0.516 0.413 s ± 0.120 3.71x
owl 30 1.439 s ± 0.446 0.447 s ± 0.158 3.22x
tezos 58 2.056 s ± 0.636 0.540 s ± 0.035 3.81x

These were collected with a pinned repository hash so that we don't time networking. The speedup is all due to amortized rev_store lookups.

re
Benchmark 1: re cache=disabled
  Time (mean ± σ):      1.912 s ±  0.576 s    [User: 1.183 s, System: 0.705 s]
  Range (min … max):    1.178 s …  2.518 s    10 runs
 
Benchmark 2: re cache=enabled
  Time (mean ± σ):     614.6 ms ± 208.4 ms    [User: 572.6 ms, System: 39.1 ms]
  Range (min … max):   369.2 ms … 818.3 ms    10 runs
 
Summary
  re cache=enabled ran
    3.11 ± 1.41 times faster than re cache=disabled
cohttp
Benchmark 1: cohttp cache=disabled
  Time (mean ± σ):      3.757 s ±  0.973 s    [User: 2.219 s, System: 1.485 s]
  Range (min … max):    2.747 s …  5.194 s    10 runs
 
Benchmark 2: cohttp cache=enabled
  Time (mean ± σ):      1.039 s ±  0.365 s    [User: 0.989 s, System: 0.045 s]
  Range (min … max):    0.791 s …  1.650 s    10 runs
 
  Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet system without any interferences from other programs.
 
Summary
  cohttp cache=enabled ran
    3.62 ± 1.58 times faster than cohttp cache=disabled
jsoo
Benchmark 1: jsoo cache=disabled
  Time (mean ± σ):      1.786 s ±  0.614 s    [User: 1.104 s, System: 0.660 s]
  Range (min … max):    1.299 s …  2.700 s    10 runs
 
  Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet system without any interferences from other programs.
 
Benchmark 2: jsoo cache=enabled
  Time (mean ± σ):     545.3 ms ± 207.5 ms    [User: 505.5 ms, System: 37.3 ms]
  Range (min … max):   373.6 ms … 835.1 ms    10 runs
 
Summary
  jsoo cache=enabled ran
    3.27 ± 1.68 times faster than jsoo cache=disabled
lsp
Benchmark 1: lsp cache=disabled
  Time (mean ± σ):      1.712 s ±  0.517 s    [User: 1.040 s, System: 0.651 s]
  Range (min … max):    1.234 s …  2.589 s    10 runs
 
Benchmark 2: lsp cache=enabled
  Time (mean ± σ):     595.6 ms ± 177.1 ms    [User: 552.2 ms, System: 39.6 ms]
  Range (min … max):   354.9 ms … 771.1 ms    10 runs
 
Summary
  lsp cache=enabled ran
    2.87 ± 1.22 times faster than lsp cache=disabled
opam
Benchmark 1: opam cache=disabled
  Time (mean ± σ):      1.002 s ±  0.362 s    [User: 0.644 s, System: 0.346 s]
  Range (min … max):    0.693 s …  1.469 s    10 runs
 
Benchmark 2: opam cache=enabled
  Time (mean ± σ):     249.4 ms ±  62.7 ms    [User: 221.7 ms, System: 26.4 ms]
  Range (min … max):   220.9 ms … 425.3 ms    10 runs
 
  Warning: The first benchmarking run for this command was significantly slower than the rest (425.3 ms). This could be caused by (filesystem) caches that were not filled until after the first run. You are already using both the '--warmup' option as well as the '--prepare' option. Consider re-running the benchmark on a quiet system. Maybe it was a random outlier. Alternatively, consider increasing the warmup count.
 
Summary
  opam cache=enabled ran
    4.02 ± 1.77 times faster than opam cache=disabled
irmin
Benchmark 1: irmin cache=disabled
  Time (mean ± σ):      3.723 s ±  0.804 s    [User: 2.247 s, System: 1.427 s]
  Range (min … max):    2.662 s …  5.117 s    10 runs
 
Benchmark 2: irmin cache=enabled
  Time (mean ± σ):      1.060 s ±  0.368 s    [User: 1.011 s, System: 0.044 s]
  Range (min … max):    0.801 s …  1.717 s    10 runs
 
  Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet system without any interferences from other programs.
 
Summary
  irmin cache=enabled ran
    3.51 ± 1.44 times faster than irmin cache=disabled
mirage
Benchmark 1: mirage cache=disabled
  Time (mean ± σ):      1.635 s ±  0.561 s    [User: 1.005 s, System: 0.610 s]
  Range (min … max):    1.021 s …  2.253 s    10 runs
 
Benchmark 2: mirage cache=enabled
  Time (mean ± σ):     346.8 ms ±  13.5 ms    [User: 319.6 ms, System: 25.4 ms]
  Range (min … max):   329.3 ms … 371.1 ms    10 runs
 
Summary
  mirage cache=enabled ran
    4.71 ± 1.63 times faster than mirage cache=disabled
eio
Benchmark 1: eio cache=disabled
  Time (mean ± σ):      1.532 s ±  0.516 s    [User: 0.940 s, System: 0.570 s]
  Range (min … max):    1.105 s …  2.325 s    10 runs
 
Benchmark 2: eio cache=enabled
  Time (mean ± σ):     413.3 ms ± 120.1 ms    [User: 383.3 ms, System: 27.8 ms]
  Range (min … max):   351.5 ms … 727.5 ms    10 runs
 
  Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet system without any interferences from other programs.
 
Summary
  eio cache=enabled ran
    3.71 ± 1.65 times faster than eio cache=disabled
owl
Benchmark 1: owl cache=disabled
  Time (mean ± σ):      1.439 s ±  0.446 s    [User: 0.903 s, System: 0.519 s]
  Range (min … max):    0.974 s …  1.998 s    10 runs
 
Benchmark 2: owl cache=enabled
  Time (mean ± σ):     446.7 ms ± 158.0 ms    [User: 405.7 ms, System: 38.8 ms]
  Range (min … max):   329.1 ms … 668.2 ms    10 runs
 
  Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet system without any interferences from other programs.
 
Summary
  owl cache=enabled ran
    3.22 ± 1.52 times faster than owl cache=disabled
tezos
Benchmark 1: tezos cache=disabled
  Time (mean ± σ):      2.056 s ±  0.636 s    [User: 1.296 s, System: 0.736 s]
  Range (min … max):    1.436 s …  2.935 s    10 runs
 
Benchmark 2: tezos cache=enabled
  Time (mean ± σ):     540.0 ms ±  34.5 ms    [User: 493.7 ms, System: 43.7 ms]
  Range (min … max):   509.3 ms … 615.9 ms    10 runs
 
Summary
  tezos cache=enabled ran
    3.81 ± 1.20 times faster than tezos cache=disabled

@Alizter
Alizter merged commit 1147ac6 into ocaml:main May 20, 2026
29 checks passed
@Alizter
Alizter deleted the pkg-rev-store-cache-version branch May 20, 2026 16:49
raphael-proust pushed a commit to ocaml/opam-repository that referenced this pull request Jun 30, 2026
CHANGES:

### Fixed

- Fix promotion failure when a target changes from a directory to a file
  between builds, causing "Is a directory" errors.
  (ocaml/dune#14371, fixes ocaml/dune#5647, fixes ocaml/dune#6575, @Alizter)

- Make `dune build @doc` pick up an odoc installed via `dune tools install
  odoc` even without `DUNE_CONFIG__LOCK_DEV_TOOL=enabled`, mirroring how
  `dune fmt` consumes a locked ocamlformat (ocaml/dune#14426, fixes ocaml/dune#14235, @mt-caret)

- Reject `(package ...)` inside a named dependency binding
  (`(deps (:name (package foo)))`). Previously this was silently accepted but
  `%{name}` would resolve to an empty path list. (ocaml/dune#14499, @Alizter)

- Fix incorrect dependency in the `.cmxs` build for libraries with
  mode-dependent foreign stubs: the rule depended on the byte stubs archive
  instead of the native one, so parallel builds could fail to find
  `-l<lib>_stubs_native`. (ocaml/dune#14500, fixes ocaml/dune#12964, @Alizter)

- Fix `dune build` failing with "No rule found" when `lock_dir` paths in
  `dune-workspace` contain a subdirectory (e.g. `(path sub/dune.lock)`).
  (ocaml/dune#14524, fixes ocaml/dune#14523, @Alizter)

- Artifact substitution repairs executable bit if it's not set correctly in the workspace
  (ocaml/dune#14556, @rgrinberg)

- Ignore `EINVAL` when accepting sockets on MacOS (ocaml/dune#14612, fixes ocaml/dune#12660, @rgrinberg)

- Validate profile names. Profile names must be non-empty and can only contain
  letters, digits, `_` and `-`. The name `_` is reserved as a wildcard in
  `(env ...)` stanzas. (ocaml/dune#14657, fixes ocaml/dune#14630, @rlepigre)

### Added

- Add `%{pkg:<package>:<section>:<path>}` pform for resolving package install
  files. Works with workspace packages, lock-file packages, and installed
  packages. (ocaml/dune#14200, fixes ocaml/dune#14193, fixes ocaml/dune#3378, @Alizter)

- Enable the relocatable compiler by default for package management (ocaml/dune#14357,
  fixes ocaml/dune#14012, @Alizter)

- Add changed source files to the `build-start` trace event for watch-mode
  restarts, showing the paths that triggered the rebuild (ocaml/dune#14396, @rgrinberg)

- Add dune's rusage information in start/finish build trace events (ocaml/dune#14402, @rgrinberg)

- Add a status message for RPC clients that manage to connect (ocaml/dune#14424, @rgrinberg)

- Allow blang expressions in the `runtest_alias` field in the `cram` stanza (ocaml/dune#14425, @rgrinberg)

- Extend the stat based cache to cache the contents of directories and not just
  source files (ocaml/dune#14469, @rgrinberg).

- Show the number of connected RPC clients in the watch mode status line
  (ocaml/dune#14489, @rgrinberg)

- Promote directory targets from experimental to generally available in 3.24
  (ocaml/dune#14579, @rgrinberg)

### Changed

- Use `/` as directory separator when appending local paths to external paths,
  making path construction consistent across platforms. (ocaml/dune#14278, @Alizter)
- On Windows, normalise process paths to `\` before passing them to
  `CreateProcessW` so that programs which scan `argv[0]` (notably `cmd.exe`)
  do not misparse mixed separators. (ocaml/dune#14278, @Alizter)

- `%{bin:NAME}` now resolves to the build artifact path rather than
  the install staging path. Rules with `%{bin:NAME}` deps additionally
  get a per-rule `.binaries` directory prepended to the action's
  `PATH`, containing correctly-named symlinks for each declared bin
  pform dep. (ocaml/dune#14432, fixes ocaml/dune#3324, @Alizter)

- Replace the Rocq language field `(stdlib ...)` with the presence-only field
  `(no_corelib)` in Rocq language 0.14. (ocaml/dune#14452, fixes ocaml/dune#14358, @Durbatuluk1701)

- Throttle sandbox creation to 250 concurrent sandboxes. (ocaml/dune#14464, @rgrinberg)

- The package solver now uses cached revision store lookups for improved
  performance. (ocaml/dune#14494, fixes ocaml/dune#12637, @Alizter, @rgrinberg)

- Remove the deprecated `(lang coq)` Coq Build Language. Use the
  Rocq Build Language (`(using rocq <version>)`) instead. Projects that
  still declare `(using coq <version>)` now get an error pointing them
  at Rocq. (ocaml/dune#14525, fixes ocaml/dune#12788, @Alizter)
@Alizter Alizter added this to the 3.24.0 milestone Jul 8, 2026
craff pushed a commit to craff/opam-repository that referenced this pull request Jul 25, 2026
CHANGES:

### Fixed

- Fix promotion failure when a target changes from a directory to a file
  between builds, causing "Is a directory" errors.
  (ocaml/dune#14371, fixes ocaml/dune#5647, fixes ocaml/dune#6575, @Alizter)

- Make `dune build @doc` pick up an odoc installed via `dune tools install
  odoc` even without `DUNE_CONFIG__LOCK_DEV_TOOL=enabled`, mirroring how
  `dune fmt` consumes a locked ocamlformat (ocaml/dune#14426, fixes ocaml/dune#14235, @mt-caret)

- Reject `(package ...)` inside a named dependency binding
  (`(deps (:name (package foo)))`). Previously this was silently accepted but
  `%{name}` would resolve to an empty path list. (ocaml/dune#14499, @Alizter)

- Fix incorrect dependency in the `.cmxs` build for libraries with
  mode-dependent foreign stubs: the rule depended on the byte stubs archive
  instead of the native one, so parallel builds could fail to find
  `-l<lib>_stubs_native`. (ocaml/dune#14500, fixes ocaml/dune#12964, @Alizter)

- Fix `dune build` failing with "No rule found" when `lock_dir` paths in
  `dune-workspace` contain a subdirectory (e.g. `(path sub/dune.lock)`).
  (ocaml/dune#14524, fixes ocaml/dune#14523, @Alizter)

- Artifact substitution repairs executable bit if it's not set correctly in the workspace
  (ocaml/dune#14556, @rgrinberg)

- Ignore `EINVAL` when accepting sockets on MacOS (ocaml/dune#14612, fixes ocaml/dune#12660, @rgrinberg)

- Validate profile names. Profile names must be non-empty and can only contain
  letters, digits, `_` and `-`. The name `_` is reserved as a wildcard in
  `(env ...)` stanzas. (ocaml/dune#14657, fixes ocaml/dune#14630, @rlepigre)

### Added

- Add `%{pkg:<package>:<section>:<path>}` pform for resolving package install
  files. Works with workspace packages, lock-file packages, and installed
  packages. (ocaml/dune#14200, fixes ocaml/dune#14193, fixes ocaml/dune#3378, @Alizter)

- Enable the relocatable compiler by default for package management (ocaml/dune#14357,
  fixes ocaml/dune#14012, @Alizter)

- Add changed source files to the `build-start` trace event for watch-mode
  restarts, showing the paths that triggered the rebuild (ocaml/dune#14396, @rgrinberg)

- Add dune's rusage information in start/finish build trace events (ocaml/dune#14402, @rgrinberg)

- Add a status message for RPC clients that manage to connect (ocaml/dune#14424, @rgrinberg)

- Allow blang expressions in the `runtest_alias` field in the `cram` stanza (ocaml/dune#14425, @rgrinberg)

- Extend the stat based cache to cache the contents of directories and not just
  source files (ocaml/dune#14469, @rgrinberg).

- Show the number of connected RPC clients in the watch mode status line
  (ocaml/dune#14489, @rgrinberg)

- Promote directory targets from experimental to generally available in 3.24
  (ocaml/dune#14579, @rgrinberg)

### Changed

- Use `/` as directory separator when appending local paths to external paths,
  making path construction consistent across platforms. (ocaml/dune#14278, @Alizter)
- On Windows, normalise process paths to `\` before passing them to
  `CreateProcessW` so that programs which scan `argv[0]` (notably `cmd.exe`)
  do not misparse mixed separators. (ocaml/dune#14278, @Alizter)

- `%{bin:NAME}` now resolves to the build artifact path rather than
  the install staging path. Rules with `%{bin:NAME}` deps additionally
  get a per-rule `.binaries` directory prepended to the action's
  `PATH`, containing correctly-named symlinks for each declared bin
  pform dep. (ocaml/dune#14432, fixes ocaml/dune#3324, @Alizter)

- Replace the Rocq language field `(stdlib ...)` with the presence-only field
  `(no_corelib)` in Rocq language 0.14. (ocaml/dune#14452, fixes ocaml/dune#14358, @Durbatuluk1701)

- Throttle sandbox creation to 250 concurrent sandboxes. (ocaml/dune#14464, @rgrinberg)

- The package solver now uses cached revision store lookups for improved
  performance. (ocaml/dune#14494, fixes ocaml/dune#12637, @Alizter, @rgrinberg)

- Remove the deprecated `(lang coq)` Coq Build Language. Use the
  Rocq Build Language (`(using rocq <version>)`) instead. Projects that
  still declare `(using coq <version>)` now get an error pointing them
  at Rocq. (ocaml/dune#14525, fixes ocaml/dune#12788, @Alizter)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

package management Dune's package management — `(pkg)` stanza, lockdirs, `dune pkg` commands

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Version and enable the lmdb cache

2 participants