Skip to content

Conversation

@kit-ty-kate
Copy link
Member

@kit-ty-kate kit-ty-kate commented Mar 29, 2025

Fixes #5448
Fixes #4056

The .opam-switch/sources directory currently stores the source of every installed packages in the following format:

  • <pkgname>: are for pinned packages
  • <pkgname>.<version>: are for the rest

In #2825 (opam 2.0.0~beta) the change from packages.dev to sources was introduced to support (as i understand it) non-pinned dev packages (e.g. ocaml-variants.5.4.0+trunk). This is a good change but this also had for side-effect to store the source of every packages regardless of whether it's a dev package or not, which i think isn't a good change given that it duplicates data that's already in the archive cache that could instead be extracted very easily (the cost of extraction vs. copy is negligible).
As a side note, extracting the sources from their tarball would be way faster on Windows that extraction + copy for the same reason detailed in #5741

As it currently stands this PR is a WIP. It compiles but still has many unsolved issues (in particular it breaks caching for non-pinned dev packages) and the reftests fail, but i'm opening it anyway to show the rough area of the code that needs to change and in case anyone wants to take over this work while i'm doing something else.

Post-WIP edit: Further improvements can be made by extracting the tarball directly into the build directory and would also f.i.x #6693, but i think it is simpler to do that separately in a future PR.

@kit-ty-kate kit-ty-kate added this to the 2.5.0~alpha1 milestone Jul 4, 2025
@kit-ty-kate
Copy link
Member Author

As a demonstration, opam clean --switch-cleanup --all which primarily cleans up these unnecessary directories, just removed 20GB of disk space on my main machine.

@kit-ty-kate kit-ty-kate force-pushed the sources-save-disk-space branch from 0781bfc to ae3a100 Compare December 22, 2025 20:49
@kit-ty-kate kit-ty-kate requested a review from rjbou December 22, 2025 20:50
@kit-ty-kate kit-ty-kate removed their assignment Dec 22, 2025
@kit-ty-kate kit-ty-kate removed the PR: WIP Not for merge at this stage label Dec 22, 2025
@kit-ty-kate kit-ty-kate marked this pull request as ready for review December 22, 2025 20:50
@kit-ty-kate kit-ty-kate changed the title [WIP] Save disk space by only caching dev packages into the internal 'sources' directory Save disk space by only caching dev packages into the internal 'sources' directory Dec 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

space savings in opam switches Feature request: reuse extracted sources

1 participant