Skip to content

Cache one copy of the install plan - #12572

Open
PaleRoses wants to merge 6 commits into
haskell:masterfrom
PaleRoses:one-cached-plan
Open

PaleRoses wants to merge 6 commits into
haskell:masterfrom
PaleRoses:one-cached-plan

Conversation

@PaleRoses

@PaleRoses PaleRoses commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

This removes the duplicate plans from cache/improved-plan. On master, the build cache holds every unit of the install plan three times: once in elaborated-plan and twice in improved-plan. The improved plan is the elaborated plan with units found in the store marked as installed.

improved-plan now holds the set of the plan's units that are in the store, keyed by the store directory and the set of configured units. The store directory is monitored as before, and the marking is redone from the set on each run. An improved-plan written by an older cabal is treated as stale and overwritten without re-solving.

This is the follow-up I offered on #12463. #12464 and #12500 have merged since, so the table's last two rows are master and this PR today. Each unit still keeps its own copy of the finalized PackageDescription, the follow-up already named in #12464.

I measured HLS at bc2bbb8e with the method from #12464, using GHC 9.12.4, -O1, assertions enabled and a populated dependency store. These are medians of six order-balanced cabal build all --dry-run runs on a shared macOS development machine. I applied the diff to 0687f8d2f. For the last column, I added one entry to the store between runs.

Version improved-plan whole cache/ No-op run Run after the store changed
master 0687f8d2f 59.7 MB 93.5 MB 1.22 s 1.79 s
This PR 0.02 MB 33.8 MB 0.797 s 0.786 s
#12464 + #12500 22.9 MB 39.0 MB 0.419 s 0.610 s
#12464 + #12500 + this PR 0.02 MB 16.2 MB 0.250 s 0.252 s

The dry-run build list and plan.json were identical with and without the PR on every run, including after store additions and removals and toggling --disable-tests and back.

AI disclosure: written with Claude Code (Fable 5.2 and Opus 5.5).


QA Notes

Build a project with a dependency from Hackage; dist-newstyle/cache/improved-plan is a few KB. Build again; the second build is up to date. Delete the dependency's directory from the store; cabal build --dry-run lists it again. StoreUnitRemoved covers this. Run the dry run again with --store-dir pointing at an empty directory; the dependency is listed, and going back to the first store it is not. StoreDirChanged covers that.

PaleRoses and others added 3 commits November 17, 2026 19:33
The improved-plan cache held the improved plan and the elaborated plan it
was made from, beside the elaborated-plan cache that already holds the
latter. The improved plan is the elaborated plan with the units found in
the store marked as installed, so improved-plan now holds only which of
the plan's units are in the store, and the marking is redone from that
set on each run. The store directory is monitored as before.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A dependency is planned until it is in the store and planned again once
it is removed from there, with the project unchanged. OfflineFlag covers
the first half; nothing covered the second.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Comment on lines +756 to +757
-- changes. So what is cached for the improved plan is only which of
-- the plan's units are in the store, not a second copy of the plan.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
-- changes. So what is cached for the improved plan is only which of
-- the plan's units are in the store, not a second copy of the plan.
-- changes. So, we only cache whether
-- each of the plan's units are in the store, rather than an entire second copy of the plan.

Maybe something like this is a bit clearer?

Comment thread changelog.d/pr-12572.md Outdated
Comment on lines +8 to +9
The `improved-plan` cache file no longer holds two more copies of the install
plan, only which of the plan's packages are in the store.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This describes implementation changes. Changelog entries IMO should describe user facing changes instead

@ulysses4ever

Copy link
Copy Markdown
Collaborator

@PaleRoses, I think the new improved-plan key misses the store. I reproduced it with this PR's head (e17d443) and a project whose dependency dep comes from a local repository:

  1. cabal --store-dir=A build all, twice, so that the cache records A's contents;
  2. cabal --store-dir=B build all, with B empty.

The plan no longer lists dep, and configure fails:

Error: [Cabal-5000]
The following package dependencies were requested
    --dependency='dep=dep-1.0-82f47099…'
however the given installed package instance does not exist.

On master, step 2 rebuilds dep into B. The key is only the plan's unit ids, which are the same whatever the store, and the cache only watches the store it last read. Adding the store directory to the key fixes it here, and the cache file stays as small:

      let store = storeDirectory cabalStoreDirLayout (pkgConfigCompiler elaboratedShared)
      storeUnits <-
        rerunIfChanged verbosity fileMonitorImprovedPlan (store, planUnits) $
          phaseImprovePlan elaboratedPlan elaboratedShared planUnits

PaleRoses and others added 3 commits December 4, 2026 20:21
A dependency built into one store is planned again when the same project
is built against a second, empty store, and is not planned once back on
the first store.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The plan's unit ids are the same whatever the store, and the cache only
watches the store it last read. So after a build with one store, a build
with another store reused the first store's answer and treated units
missing from the second store as installed. The store directory for the
plan's compiler is now part of the key.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Reword the comment above the cached improvement step as suggested in
review, and say in the changelog entry what changes for a user rather
than how the cache is built.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@PaleRoses

Copy link
Copy Markdown
Contributor Author

@ulysses4ever thanks, I reproduced it with your steps. The PR narrowed the cache key to the plan's unit ids and dropped the store directory. I took your fix in 544a1c7 and added a test that switches stores and then switches back.

@TeofilC sorry for the delay! I put both suggestions in b8444a1.

@mergify mergify Bot added the 1️⃣ more approval needed Set by Mergify: has one of the two required approvals label Dec 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

1️⃣ more approval needed Set by Mergify: has one of the two required approvals

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants