Skip to content

Configure the compiler ProgramDb once per project#11768

Open
sheaf wants to merge 1 commit intohaskell:masterfrom
sheaf:conf-comp-progs
Open

Configure the compiler ProgramDb once per project#11768
sheaf wants to merge 1 commit intohaskell:masterfrom
sheaf:conf-comp-progs

Conversation

@sheaf
Copy link
Copy Markdown
Collaborator

@sheaf sheaf commented Apr 27, 2026

This PR ensures we configure the compiler program database (constituted of ghc and attendant programs such as ghc-pkg, haddock, toolchain programs such as ar, ld etc) ahead of time within cabal-install, so that we don't need to reconfigure programs such as ghc, ghc-pkg, haddock etc once per package within Cabal.

This should be a net performance win without any other change in behaviour.


Template Α: This PR modifies behaviour or interface

  • Patches conform to the coding conventions.
  • Any changes that could be relevant to users have been recorded in the changelog.
  • The documentation has been updated, if necessary.
  • No manual QA notes necessary (no change to the command line interface).
  • Testing approach: the subtle tests like BuildToolPaths ensure we don't regress when users pass --with-alex (for example).

@sheaf sheaf force-pushed the conf-comp-progs branch 3 times, most recently from f4bd9b8 to 7cfb145 Compare April 28, 2026 09:16
@sheaf sheaf force-pushed the conf-comp-progs branch from 7cfb145 to 83ef876 Compare April 29, 2026 12:03
@sheaf sheaf marked this pull request as ready for review April 29, 2026 12:04
@sheaf
Copy link
Copy Markdown
Collaborator Author

sheaf commented Apr 29, 2026

This is a thorny area, see e.g. #10692 (commits 24f8395 and 2c19bf3) and #11373 (040a97d). So I would appreciate a careful review.

@sheaf
Copy link
Copy Markdown
Collaborator Author

sheaf commented Apr 30, 2026

I have put up a spreadsheet here, compiling pandoc from scratch and using the --build-timings feature from #11769.

Base average time spent in configure: 2.9 seconds.
With this patch: it goes down to 1.2 seconds.
With #11767: it goes down to 1.7 seconds.
With both: it goes down to 0.15 seconds.

@Mikolaj
Copy link
Copy Markdown
Member

Mikolaj commented Apr 30, 2026

This really looks tricky --- so few changes, but such a great effect.

Would it possible to add some tests that try to break things by performing a few scenarios that previously took many configuration invocations and now that just one? Maybe to these twice for a good measure?

A question: does the "once per project" mean once per project per cabal run, or until cabal clean happens or something else invalidates things?

@Mikolaj Mikolaj added the intricate potentially very hard to review, but worth it label Apr 30, 2026
$ projectConfigProvenance projectConfig
]

configureCompiler
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Are you able to add haddocks to configureCompiler, including what is in ProgramDb and when it is set up and cleared?

, projectConfigBuildOnly
}
(compiler, platform, progdb)
(compiler, platform, compilerprogdb)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The absence of a casing change in compilerprogdb is a bit odd. Maybe compilerProgDb? Is there a problem with the progdb name?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This one could be called unconfiguredProgDb and the other one progdb or progDb, once configured.

-> Platform
-> Compiler
-> ProgramDb
-- ^ **Configured** compiler program database (ghc, ghc-pkg, haddock, ld, etc)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This doesn't render well:

Image

Is that markdown bold in place of haddocks bold?

@@ -1640,7 +1641,7 @@ elaborateInstallPlan
   -> Platform
   -> Compiler
   -> ProgramDb
-  -- ^ **Configured** compiler program database (ghc, ghc-pkg, haddock, ld, etc)
+  -- ^ __Configured__ compiler program database (ghc, ghc-pkg, haddock, ld, etc)
   -> Maybe PkgConfigDb

prependProgramSearchPath verbosity
(useExtraPathEnv options)
(useExtraEnvOverrides options) =<<
mkProgramDb verbHandles flags -- Passes user-supplied arguments to e.g. GHC
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is the comment "Passes user-supplied arguments to e.g. GHC" no longer relevant?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

That's part of configuring a program, isn't it?

-- | Try to configure a specific program. If the program is already included in
-- the collection of unconfigured programs then we use any user-supplied
-- location and arguments.
configureUnconfiguredProgram
:: Verbosity
-> Program
-> ProgramDb
-> IO (Maybe ConfiguredProgram)

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

Labels

attention: needs-review intricate potentially very hard to review, but worth it

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants