threads / discuss / 24430

git diff slow after initial checkout

Subject: git diff slow after initial checkout

## tl;dr

One message between Jul 18, 2010 and Jul 18, 2010.

replies: 0people: 1as markdown or json

Michel Lespinasse· Jul 18, 2010, 14:17 UTC · lore
Hi,
I am seeing a slow 'git diff' when doing the following with git 1.7.0.4:

% git clone /path/to/repo % cd repo % git checkout e0d960b % time git diff | cat git diff 0.15s user 0.30s system 96% cpu 0.468 total cat 0.00s user 0.00s system 0% cpu 0.467 total % strace -o ../strace.before git diff | cat % touch .git/index % time git diff | cat git diff 0.00s user 0.00s system 0% cpu 0.006 total cat 0.00s user 0.00s system 0% cpu 0.005 total % strace -o ../strace.after git diff | cat

The first diff is ~100 times slower than what git has gotten me used to. If I run the diff multiple times, it stays slow every time until I touch the index.

The strace shows that before I touch the index, 'git diff' mmaps .git/index and then does an lstat/open/read/close loop on every file in the repository. After I touch the index, 'git diff' only does an lstat on every file.

It looks like 'git checkout' should touch the index file after it's done ?

Alternatively, maybe 'git diff' should do that after it notices there are no modified files ?

Is this fixed with a more recent version of git ? (in RelNotes-1.7.1.1.txt I see something about 'git status' stopped refreshing the index by mistake in git 1.7.1, which sounds like the same problem but in a different place ?)

-- 
Michel "Walken" Lespinasse
A program is never fully debugged until the last user dies.

← back to recent threads