]> git.ipfire.org Git - thirdparty/git.git/commit - read-cache.c
read-cache.c: optimize reading index format v4
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Wed, 26 Sep 2018 19:54:36 +0000 (15:54 -0400)
committerJunio C Hamano <gitster@pobox.com>
Wed, 26 Sep 2018 22:19:49 +0000 (15:19 -0700)
commit252d079cbd27ca442d94535e3979145eceaf082b
tree4ca57a16478ca4850ed27a6258dc66a2b00e730d
parentfe8321ec057f9231c26c29b364721568e58040f7
read-cache.c: optimize reading index format v4

Index format v4 requires some more computation to assemble a path
based on a previous one. The current code is not very efficient
because

 - it doubles memory copy, we assemble the final path in a temporary
   first before putting it back to a cache_entry

 - strbuf_remove() in expand_name_field() is not exactly a good fit
   for stripping a part at the end, _setlen() would do the same job
   and is much cheaper.

 - the open-coded loop to find the end of the string in
   expand_name_field() can't beat an optimized strlen()

This patch avoids the temporary buffer and writes directly to the new
cache_entry, which addresses the first two points. The last point
could also be avoided if the total string length fits in the first 12
bits of ce_flags, if not we fall back to strlen().

Running "test-tool read-cache 100" on webkit.git (275k files), reading
v2 only takes 4.226 seconds, while v4 takes 5.711 seconds, 35% more
time. The patch reduces read time on v4 to 4.319 seconds.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
read-cache.c