Stats in Git
From: Marius Storm-Olsen <hidden>
Date: 2016-06-15 22:43:32
Subsystem:
the rest · Maintainer:
Linus Torvalds
I was checking out the performance situation with Git on Windows, and
found out that the Posix stat functions on Windows are just obscenely
slow. We really can't use them, at least on in Git. So, I made a patch
for the MinGW version, which I'll post right after this mail.
However, while look at that whole stat'ing situation in git, I saw
that doing 'git status' actually stats all the files _thrice_!
Yup, that's not 1 time, or 2 times, but actually 3(!) times before
'git status' is content!
I know that git-status is a script, so I think this clearly indicates
that git-status is a prime candidate for a built-in ;-)
I haven't looked into details as to why it stats the files so many
times. I guess someone more experienced in Git core could give an
opinion, if by writing git-status as a builtin it would be possible to
only stat the files once. It would have a huge impact on Windows where
stats are inheritly much slower than on Linux.
By applying the diff below, you can see for yourself what happens when
you stat the repo created with Moe's script:
mkdir bummer
cd bummer
for ((i=0;i<100;i++)); do
mkdir $i && pushd $i;
for ((j=0;j<1000;j++)); do
echo "$j" >$j; done; popd;
done
$ git status 2>&1 | wc -l
300137
Fast on Linux now, but still quite slow on Windows..
--
.marius
diff --git a/git-compat-util.h b/git-compat-util.h
index ca0a597..6b6405c 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h@@ -369,4 +369,23 @@ static inline int strtoul_ui(char const *s, int base, unsigned int *result) return 0; } +static inline int git_lstat(const char *file_name, struct stat *buf) +{ + fprintf(stderr, "lstat: %s\n", file_name); + return lstat(file_name, buf); +} +static inline int git_fstat(int fd, struct stat *buf) +{ + fprintf(stderr, "fstat: %d\n", fd); + return fstat(fd, buf); +} +static inline int git_stat(const char *file_name, struct stat *buf) +{ + fprintf(stderr, "stat: %s\n", file_name); + return stat(file_name, buf); +} +#define lstat(x,y) git_lstat(x,y) +#define fstat(x,y) git_fstat(x,y) +#define stat(x,y) git_stat(x,y) + #endif