Don't re-run the solver unnecessarily

Open
#12,119 2 comments 2 reactions 0 assignees View on GitHub

Maintainers usually reply within 3 days

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Refactor
Clarity
Mostly clear
Activity status
Quiet
Tech stack
haskell
Domain
build-system

Research direction

Start in Distribution.Client.ProjectPlanning.rebuildInstallPlan, especially phaseRunSolver and its localPackages input, then inspect Distribution.Solver.Modular.Index.PInfo and ConfiguredConversion.convCP. Trace consumers of solverPkgSource and verify that solver reruns no longer depend on unrelated GenericPackageDescription changes while the solver result still updates SourcePackages correctly.

Written by the indexing model from the issue text.

Description

attention: pr-welcome cabal-install: cmd/build recompilation type: bug type: discussion type: performance

The recompilation logic for the solver triggers recompilation if anything in the package description changes. See Distribution.Client.ProjectPlanning.rebuildInstallPlan:

      phaseRunSolver
        :: ProjectConfig
        -> (Compiler, Platform, ProgramDb)
        -> [PackageSpecifier UnresolvedSourcePackage]
        -> InstalledPackageIndex
        -> Rebuild (SolverInstallPlan, Maybe PkgConfigDb, IndexUtils.TotalIndexState, IndexUtils.ActiveRepos)
      phaseRunSolver
        projectConfig@ProjectConfig
          { projectConfigShared
          , projectConfigBuildOnly
          }
        (compiler, platform, progdb)
        localPackages
        installedPackages =
          rerunIfChanged
            verbosity
            fileMonitorSolverPlan
            ( solverSettings
            , localPackages -- !!!
            , localPackagesEnabledStanzas
            , compiler
            , platform
            , programDbSignature progdb
            )
            $ do ...

We re-run the solver if localPackages changes, and this includes all the fields of SourcePackage, including the entire GenericPackageDescription!!!

data SourcePackage loc = SourcePackage
  { srcpkgPackageId     :: PackageId
  , srcpkgDescription   :: GenericPackageDescription
  , srcpkgSource        :: loc
  , srcpkgDescrOverride :: PackageDescriptionOverride
  }
  deriving (Eq, Show, Generic)

The principled way to fix this would be to change the input of the solver entirely. The solver only needs the information that's in the Distribution.Solver.Modular.Index.PInfo datatype:

data PInfo = PInfo (FlaggedDeps PN)
                   (Map ExposedComponent ComponentInfo)
                   FlagInfo
                   (Maybe FailReason)

data ComponentInfo = ComponentInfo {
    compIsVisible   :: IsVisible
  , compIsBuildable :: IsBuildable
  }

We should project down to these PInfos instead of passing SourcePackages that contain full package description. This will require reworking consumers of the solverPkgSource constructed by Distribution.Solver.Modular.ConfiguredConversion.convCP which uses the solver result to modify SourcePackages.

Dominant language
Haskell
Stars
1.8k
Forks
766
Avg merge
5d 21h
Merged PRs (30d)
27

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from haskell/cabal

All issues in haskell/cabal

Similar issues

More Haskell issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.