I recently cloned a remote repo in which some git
commands run extremely slowly. For example, running
git diff --quiet
...takes ~40 s. (For what it's worth, the repo is clean. I am using git
version 2.20.1.)
While trying to figure out what's causing this sluggishness, I have bumped into a handful of procedures that abolish it, though I have no idea why.
Of these procedures, the simplest/quickest one I've found is this: (starting from a freshly-cloned instance of the repo) create a branch off master
, and checkout it out. After this, if I check out master
once more, now git diff --quiet
finishes quickly (under 50ms).
Below is an example interaction, showing timing information for the various opertions1:
rm -rf ./"$REPONAME" # 0.174 s
git clone "$URL" # 54.118 s
cd ./"$REPONAME" # 0.007 s
git diff --quiet # 39.438 s
git branch VOODOO # 0.032 s
git checkout VOODOO # 31.247 s
git diff --quiet # 0.014 s
git checkout master # 0.034 s
git diff --quiet # 0.012 s
As I've already stressed, this is only one of several possible procedures that "fix" the repo, and they are all equally mysterious to me. This only happens to be the simplest/quickest one I've found.
The above sequence of timings is very reproducible (i.e. I get roughly the same timings every time I run that specific sequence exactly as shown).
It is, however, very sensitive to seemingly small variations. For example if I replace the git branch VOODOO; git checkout VOODOO
with git checkout -b VOODOO
, the subsequent profile of timings changes radically:
rm -rf ./"$REPONAME" # 0.015 s
git clone "$URL" # 45.312 s
cd ./"$REPONAME" # 0.007 s
git diff --quiet # 46.145 s
git checkout -b VOODOO # 42.363 s
git diff --quiet # 41.180 s
git checkout master # 47.345 s
git diff --quiet # 0.018 s
I would like to figure out what is going on. How can I troubleshoot the matter further?
Is there a permanent ("committable") way to "fix" the repo? (By "fix" I mean: get rid of the long delays for git diff --quiet
, git checkout ...
, etc.)
(Incidentally, git gc
won't fix the repo, even transiently; I tried it.)
I figure that what ends up "fixing" the repo is that git
gets around to building and caching some auxiliary data structure that allows it to perform some operations efficiently. If this hypothesis is correct, then my question can be rephrased as: what is the most direct way to cause git
to build such auxiliary data structure?
EDIT: One additional bit of information that may shed light on the above is that this repo contains one exceptionally large (1GB) file. (This explains the slowness of the git clone
step. I don't know if this has anything to do with the slowness of git diff --quiet
, etc., and if so, how.)
1 Needless to say, I've named the branch VOODOO
to reflect my ignorance of what's going on.