Speed up manifest source for large repos #407
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR take some steps to address the slow runtime of the manifest source when using a generated manifest strategy as opposed to a hardcoded file with dependency mappings. In a test repo with 54k files reported by
git ls-files
, the changes here dropped the runtime from so-long-I-ctrl-C'd to a max of 8s.From some very inconclusive maths this also showed to reduce the time in small-medium sized projects; running the manifest tests with this change increased the assertions/s and reduced the overall runtime just a bit. Nothing super conclusive but it at least didn't increase the runtime 😄
The primary issue for large repos was the massive number of
File.exist?
calls that were being issued, one for every file coming fromgit ls-files
. Verification that the file actually exists on disk is necessary because the tool can be run with deleted files that have not been committed, meaning thatgit ls-files
can return files that don't exist.By using set intersection and loading the entire file system under the project root into memory the runtime is drastically reduced at the expense of more memory usage. For the majority of projects this should be minimal, and for very large projects this should still be a reasonable tradeoff.
Using a single set with
each_with_object
instead ofreduce
results in less object allocations and set enumeration copies, which dropped another couple seconds after the above. It won't affect the memory increase caused from (1), but it does reduce runtimes a bit further.