From: Linus Torvalds <torvalds@linux-foundation.org>
To: Junio C Hamano <gitster@pobox.com>,
Git Mailing List <git@vger.kernel.org>
Subject: [PATCH] Avoid unnecessary 'lstat()' calls in 'get_stat_data()'
Date: Sat, 9 May 2009 15:09:54 -0700 (PDT) [thread overview]
Message-ID: <alpine.LFD.2.01.0905091501460.3586@localhost.localdomain> (raw)
From: Linus Torvalds <torvalds@linux-foundation.org>
Date: Sat, 9 May 2009 14:57:30 -0700
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 <torvalds@linux-foundation.org>
---
I sent this as part of the "make 'git checkout' preload the index" patch,
but since the preloading was of somewhat dubious value, and this part of
it is not, I'll just send this one-liner as an "obvious performance fix".
diff-lib.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/diff-lib.c b/diff-lib.c
index a310fb2..0aba6cd 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -214,7 +214,7 @@ static int get_stat_data(struct cache_entry *ce,
const unsigned char *sha1 = ce->sha1;
unsigned int mode = ce->ce_mode;
- if (!cached) {
+ if (!cached && !ce_uptodate(ce)) {
int changed;
struct stat st;
changed = check_removed(ce, &st);
--
1.6.3
next reply other threads:[~2009-05-09 22:13 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-05-09 22:09 Linus Torvalds [this message]
2009-05-09 22:41 ` [PATCH] Teach 'git checkout' to preload the index contents Linus Torvalds
2009-05-10 4:20 ` [PATCH] Avoid unnecessary 'lstat()' calls in 'get_stat_data()' Junio C Hamano
2009-05-10 16:50 ` Linus Torvalds
2009-05-10 17:45 ` Johannes Schindelin
2009-05-10 18:40 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=alpine.LFD.2.01.0905091501460.3586@localhost.localdomain \
--to=torvalds@linux-foundation.org \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).