aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Potapov <dpotapov@gmail.com>2010-02-21 09:32:19 +0300
committerJunio C Hamano <gitster@pobox.com>2010-02-21 11:39:10 -0800
commitea68b0ce9f8ce8da3e360aed3cbd6720159ffbee (patch)
tree0b2e4380a4bcd4933c0f85440c033def07fc090a
parente923eaeb901ff056421b9007adcbbce271caa7b6 (diff)
downloadgit-ea68b0ce9f8ce8da3e360aed3cbd6720159ffbee.tar.gz
git-ea68b0ce9f8ce8da3e360aed3cbd6720159ffbee.tar.xz
hash-object: don't use mmap() for small files
Using read() instead of mmap() can be 39% speed up for 1Kb files and is 1% speed up 1Mb files. For larger files, it is better to use mmap(), because the difference between is not significant, and when there is not enough memory, mmap() performs much better, because it avoids swapping. Signed-off-by: Dmitry Potapov <dpotapov@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--sha1_file.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/sha1_file.c b/sha1_file.c
index 657825e14..037515960 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -2434,6 +2434,8 @@ static int index_mem(unsigned char *sha1, void *buf, size_t size,
return ret;
}
+#define SMALL_FILE_SIZE (32*1024)
+
int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object,
enum object_type type, const char *path)
{
@@ -2448,6 +2450,14 @@ int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object,
else
ret = -1;
strbuf_release(&sbuf);
+ } else if (size <= SMALL_FILE_SIZE) {
+ char *buf = xmalloc(size);
+ if (size == read_in_full(fd, buf, size))
+ ret = index_mem(sha1, buf, size, write_object, type,
+ path);
+ else
+ ret = error("short read %s", strerror(errno));
+ free(buf);
} else if (size) {
void *buf = xmmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
ret = index_mem(sha1, buf, size, write_object, type, path);