Improve performance - Avoid repeated git diff calls #154
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.
Context
I was measuring why
talisman
took lot of time when there are lot of git additions involved. I was trying to seggregate each call and the time it took.As a test, assume we
git add
thevendor/
directory of talisman (~400 additions)These were the main observation:
The command took 8 seconds inspite of changing detectors to use channels. The main culprit was
GetDiffForStagedFiles
. Looking into it, I saw that there were 400git diff --staged
commands being made for each single file.Solution
git diff --staged
which gives the complete output of allgit diff --staged {FILENAME}
combined together.This is structured format and each file's diff starts with that header. So the approach,
fetchStagedDiff
which does a few trimming and adds the staged addition (now renamed toextractAdditions
).Performance post that:
Fetching git diff is 15X faster.
Talisman is ~4X faster now.
Questions:
gitrepo_test
passes. I slightly modified to not panic on assertion failures.For future scope, all pattern matching can be improved by not looping over all patterns and trying to match through a single pass. But that can be made as a separate PR (which can reduce PatternDetector's time taken, second highest time taken, further)