From ab8a0402aeac9767e5bb1b022a6c9ad27cf78f32 Mon Sep 17 00:00:00 2001 From: David Michael Barr Date: Wed, 12 Sep 2012 14:26:31 +1000 Subject: [PATCH] odb_pack: try lookup before refreshing packs This reduces the rate of syscalls for the common case of sequences of object reads from the same pack. Best of 5 timings for libgit2_clar before this patch: real 0m5.375s user 0m0.392s sys 0m3.564s After applying this patch: real 0m5.285s user 0m0.356s sys 0m3.544s 0.6% improvement in system time. 9.2% improvement in user time. 1.7% improvement in elapsed time. Confirmed a 0.6% reduction in number of system calls with strace. Expect greater improvement for graph-traversal with large packs. --- src/odb_pack.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/odb_pack.c b/src/odb_pack.c index 6e3d3eefd..d33d06456 100644 --- a/src/odb_pack.c +++ b/src/odb_pack.c @@ -268,13 +268,13 @@ static int pack_entry_find(struct git_pack_entry *e, struct pack_backend *backen int error; unsigned int i; - if ((error = packfile_refresh_all(backend)) < 0) - return error; - if (backend->last_found && git_pack_entry_find(e, backend->last_found, oid, GIT_OID_HEXSZ) == 0) return 0; + if ((error = packfile_refresh_all(backend)) < 0) + return error; + for (i = 0; i < backend->packs.length; ++i) { struct git_pack_file *p;