Refactor & optimise construction of index cache
commitdb1ef505ab898d0c6b5cca54bb7e222ff5f4e6ae
authorHerbert Valerio Riedel <hvr@gnu.org>
Wed, 21 Sep 2016 05:55:48 +0000 (21 07:55 +0200)
committerHerbert Valerio Riedel <hvr@gnu.org>
Wed, 21 Sep 2016 12:25:39 +0000 (21 14:25 +0200)
tree1c4f19749065bbbbddf4abc259cf40af4a37929e
parent92c51628e4bb5b71b0f6a9e77a3903de2db1f579
Refactor & optimise construction of index cache

This commit was motivated by @dcoutts' code-review comment:

> Originally with using the `Sec.directoryEntries` that gave us only the
> final version of each file, ie not all intermediate revisions. And
> previously our strategy was to go through the final versions of each
> file, in file order, and lookup just the ones we're interested in (which
> in practice is 99% of them).
>
> Now for the new cache we want to go through all revisions, which means
> all entries in file order. So instead of using `Sec.directoryEntries`
> which reads from the tar index, we go straight for `Sec.directoryFirst`
> which is block 0 and iterate through, using `lazyUnfold`.
>
> But we can now significantly simplify this and do it more
> efficiently. Note that `indexLookupEntry` and `indexLookupFileEntry` are
> expensive operations that seek in the tar file and read the tar entry at
> that point. So lets do it exactly once per entry. The current code does
> it once in the `lazyUnfold indexLookupEntry` and then again in `mk`. But
> the old `mk` only did that because it had not previously looked up the
> entry.
cabal-install/Distribution/Client/IndexUtils.hs