Keep a running InstalledPackageIndex to skip expensive per-package ghc-pkg calls#11767
Keep a running InstalledPackageIndex to skip expensive per-package ghc-pkg calls#11767sheaf wants to merge 1 commit intohaskell:masterfrom
Conversation
660164a to
f27441c
Compare
We extract 'computePackageInfoFromIndex' from the Cabal 'computePackageInfo' function, which allows cabal-install to use a running 'InstalledPackageIndex' instead of having to repeatedly query ghc-pkg (once per package). Several cabal-install functions now pass around a 'TVar InstalledPackageIndex' which keeps track of the 'InstalledPackageIndex' used for building a project. Each time a dependency gets registered, we update this 'TVar', and read from it to obtain an 'InstalledPackageIndex' to pass to the Cabal configure function, skipping slow calls to 'ghc-pkg'. For more details, please see Note [Per-project InstalledPackageIndex] in Distribution.Client.ProjectBuilding.
|
This was a bit subtle to write, and getting it wrong means that we pass an incomplete or incorrect |
|
Since the title of this PR mentions replacing "expensive" ghc-pkg calls, I am curious if there is any fast, back-of-envelope timings of what sorts of gains one can expect from this change. |
I will get back to you with more precise measurements but for typical packages this can save over half of the time spent in configure. Taken with #11768 I am seeing typical configure times go from ~3s to ~0.5s. |
Mikolaj
left a comment
There was a problem hiding this comment.
Great job! Looks plausible to me.
ulysses4ever
left a comment
There was a problem hiding this comment.
The caching strategy is straightforward and looks good. The relation to some ghc-pkg calls is indirect (you can't see it in the diff), so it's unclear to me. I'd appreciate if it was clarified, to which end I leave a comment for the changelog below. Thanks!
|
|
||
| `cabal-install` now keeps a running `InstalledPackageIndex` that it updates | ||
| as packages in a project get built. This allows skipping expensive `ghc-pkg` | ||
| calls (one per elaborated package being configured). |
There was a problem hiding this comment.
"expensive ghc_pkg calls that we make when…"?
| readCachedRegistration PackageFileMonitor{pkgFileMonitorReg} = do | ||
| result <- checkFileMonitorChanged pkgFileMonitorReg "." () | ||
| return $ case result of | ||
| MonitorUnchanged mIpi _ -> mIpi | ||
| MonitorChanged _ -> Nothing |
There was a problem hiding this comment.
Could be done without result or return. Use of <&> instead of <$> would require another import.
| readCachedRegistration PackageFileMonitor{pkgFileMonitorReg} = do | |
| result <- checkFileMonitorChanged pkgFileMonitorReg "." () | |
| return $ case result of | |
| MonitorUnchanged mIpi _ -> mIpi | |
| MonitorChanged _ -> Nothing | |
| readCachedRegistration PackageFileMonitor{pkgFileMonitorReg} = | |
| \case MonitorUnchanged mIpi _ -> mIpi; MonitorChanged _ -> Nothing | |
| <$> checkFileMonitorChanged pkgFileMonitorReg "." () |
| -------------------------------------------------------------------------------- | ||
|
|
There was a problem hiding this comment.
Is this separator between imports and the rest of the module needed?
Building on the in-library refactor that landed in 6867dd5, this patch extracts
computePackageInfoFromIndexfrom the CabalcomputePackageInfofunction, which allows cabal-install to use a runningInstalledPackageIndexinstead of having to repeatedly query ghc-pkg, once per package.Several cabal-install functions now pass around a
TVar InstalledPackageIndexwhich keeps track of theInstalledPackageIndexused for building a project. Each time a dependency gets registered, we update thisTVar, and read from it to obtain anInstalledPackageIndexto pass to the Cabal configure function, skipping slow calls toghc-pkg.Template Α: This PR modifies behaviour or interface
ghc-pkgfar less.