Skip to content

Commit 658dd48

Browse files
torvaldsgitster
authored andcommitted
Avoid unnecessary 'lstat()' calls in 'get_stat_data()'
When we ask get_stat_data() to get the mode and size of an index entry, we can avoid the lstat() call if we have marked the index entry as being uptodate due to earlier lstat() calls. This avoids a lot of unnecessary lstat() calls in eg 'git checkout', where the last phase shows the differences to the working tree (requiring a diff), but earlier phases have already verified the index. On the kernel repo (with a fast machine and everything cached), this changes timings of a nul 'git checkout' from - Before (best of ten): 0.14user 0.05system 0:00.19elapsed 100%CPU (0avgtext+0avgdata 0maxresident)k 0inputs+0outputs (0major+13237minor)pagefaults 0swaps - After 0.11user 0.03system 0:00.15elapsed 98%CPU (0avgtext+0avgdata 0maxresident)k 0inputs+0outputs (0major+13235minor)pagefaults 0swaps so it can obviously be noticeable, although equally obviously it's not a show-stopper on this particular machine. The difference is likely larger on slower machines, or with operating systems that don't do as good a job of name caching. Signed-off-by: Linus Torvalds <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f29d669 commit 658dd48

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

diff-lib.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ static int get_stat_data(struct cache_entry *ce,
222222
const unsigned char *sha1 = ce->sha1;
223223
unsigned int mode = ce->ce_mode;
224224

225-
if (!cached) {
225+
if (!cached && !ce_uptodate(ce)) {
226226
int changed;
227227
struct stat st;
228228
changed = check_removed(ce, &st);

0 commit comments

Comments
 (0)