Repository navigation
Conversation
toComponentLocalBuildInfos built a graph of every installed package, unioned it with the component graph and took the closure. Only installed packages reachable from the components can be in that closure, so look those up by UnitId and build the graph from them. The closure is unchanged. Addresses haskell#12546.
a8bdcf2 to
1a3cba1
Compare
sheaf
left a comment
There was a problem hiding this comment.
This looks great, just a few small suggestions. Thanks for doing this!
| combined_graph = Graph.unionRight external_graph internal_graph | ||
| local_graph = | ||
| fromMaybe (error "toComponentLocalBuildInfos: closure returned Nothing") $ | ||
| Graph.closure combined_graph (map nodeKey graph) |
There was a problem hiding this comment.
Why do we still need to compute a closure? Didn't the DFS above already compute it?
There was a problem hiding this comment.
The DFS only decides which installed packages go into the graph. I kept Graph.closure so that local_graph comes out in the same order as before, since PackageIndex.fromList keeps that order for instances of the same package. Happy to build it directly if the order doesn't matter there.
| reachable_installed = go Map.empty (concatMap nodeNeighbors graph) | ||
| where | ||
| go seen [] = Map.elems seen | ||
| go seen (uid : uids) | ||
| | uid `Set.member` internal_keys || uid `Map.member` seen = go seen uids | ||
| | Just pkg <- PackageIndex.lookupUnitId installedPackageSet uid = | ||
| go (Map.insert uid pkg seen) (nodeNeighbors pkg ++ uids) | ||
| | otherwise = go seen uids |
There was a problem hiding this comment.
Could we refactor Distribution.Simple.PackageIndex.dependencyClosure to avoid re-implementing that logic here, e.g. by having a new function that returns the two lists ("completed", "failed") separately? We'd use that new function and dependencyClosure just wraps it in Either as it does now.
This would allow there to be a single place in the code where a dependency closure is computed.
There was a problem hiding this comment.
Done in ae70a07: dependencyClosureAndMissing returns the closure and the missing UnitIds separately, dependencyClosure wraps it, and this calls it on the index without the components' UnitIds. The results are the same on the 3,600 random cases; it takes 3.8 ms rather than 2.8 ms per component at 20,000 installed packages (36 ms on master).
Add dependencyClosureAndMissing, which returns the closure and the missing UnitIds separately, define dependencyClosure with it, and use it in toComponentLocalBuildInfos instead of a separate traversal.
|
I had to manually turn off assertions to get similar behaviour to the numbers you reported.
|
insert checks the PackageIndex invariant, which is not compiled out (-fno-ignore-asserts), so building the closure with one insert per package was quadratic. Collect the packages and use fromList once, which gives the same index. Also drop the deleteUnitId calls: an installed package shadowed by a component is replaced by Graph.unionRight, so it does not change the closure.
|
Thanks, I missed that: my benchmark linked GHC's installed Cabal. In b1970ce, |
Addresses part of #12546.
toComponentLocalBuildInfosbuilt aGraphof every installed package, unioned it with the component graph and took the closure. Only installed packages reachable from the components can be in that closure, so this looks them up byUnitIdand builds the graph from those. Installed packages with the sameUnitIdas a component are skipped, sinceunionRightreplaced them, and missing dependencies are still reported byGraph.broken.The closure is the same, including its order, which
PackageIndex.fromListdepends on for instances of the same package. I compared the old and new code on 3,600 random installed-package graphs, with shared package names, shadowed keys and missing dependencies: the closure, thePackageIndexbuilt from it andGraph.brokenwere identical in every case.Time for this step, per component (synthetic package index, GHC 9.10.3, Windows 11):
This doesn't touch the other costs in #12546:
PackageIndex.fromListanddependencyInconsistenciesstill run on the closure for each component.The Backpack, BuildDeps, InternalLibraries and ConfigureComponent tests pass, except
Backpack/Includes2andInternalLibraries/setup-gen-script, which fail the same way on master on my Windows machine.Template B: This PR does not modify behaviour or interface