git/list[1] front-page[2] threads[3] people[4] search[5] about
 

git diff slow after initial checkout

From
MLMichel Lespinasse <walken@google.com>
Date
Jul 18, 2010, 14:17 UTC
Message-ID
<20100718141719.GA32660@google.com>
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.
Message 1 of 1 in “git diff slow after initial checkout”
  1. Michel LespinasseJul 18, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.