Speed up 'closure' computation in `ghc-pkg`
Closes #27275 (closed)
The profile has been obtained using default flavour, and the package db has 1800 entries.
> /home/hugin/Documents/haskell/ghc-homes/ghc/_default/stage1/bin/ghc-pkg -f ~/.local/state/cabal/store/ghc-10.1.20260513-inplace/package.db/ list | wc -l
1762
Before this commit:
> hyperfine '/home/hugin/Documents/haskell/ghc-homes/ghc/_default/stage1/bin/ghc-pkg -f ~/.local/state/cabal/store/ghc-10.1.20260513-inplace/package.db/ list'
Benchmark 1: /home/hugin/Documents/haskell/ghc-homes/ghc/_default/stage1/bin/ghc-pkg -f ~/.local/state/cabal/store/ghc-10.1.20260513-inplace/package.db/ list
Time (mean ± σ): 394.8 ms ± 12.9 ms [User: 340.4 ms, System: 47.2 ms]
Range (min … max): 377.7 ms … 408.8 ms 10 runs
After this MR:
> hyperfine '/home/hugin/Documents/haskell/ghc-homes/ghc/_default/stage1/bin/ghc-pkg -f ~/.local/state/cabal/store/ghc-10.1.20260513-inplace/package.db/ list'
Benchmark 1: /home/hugin/Documents/haskell/ghc-homes/ghc/_default/stage1/bin/ghc-pkg -f ~/.local/state/cabal/store/ghc-10.1.20260513-inplace/package.db/ list
Time (mean ± σ): 186.4 ms ± 4.9 ms [User: 136.1 ms, System: 45.2 ms]
Range (min … max): 179.2 ms … 198.8 ms 16 runs
Edited by Hannes Siebenhandl