[PATCH v2 3/3] read-cache: micro-optimize expand_name_field() to speed up V4 index parsing.
From: Ben Peart <hidden>
Date: 2018-08-29 15:25:42
Subsystem:
the rest · Maintainer:
Linus Torvalds
- 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() I used p0002-read-cache.sh to generate some performance data on the cumulative impact: 100,000 files Test HEAD~3 HEAD --------------------------------------------------------------------------- read_cache/discard_cache 1000 times 14.08(0.03+0.09) 8.71(0.01+0.09) -38.1% 1,000,000 files Test HEAD~3 HEAD ------------------------------------------------------------------------------ read_cache/discard_cache 1000 times 201.77(0.03+0.07) 149.68(0.04+0.07) -25.8% Suggested by: Nguyễn Thái Ngọc Duy [off-list ref] Signed-off-by: Ben Peart <redacted> --- read-cache.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/read-cache.c b/read-cache.c
index f768004617..f5e7c86c42 100644
--- a/read-cache.c
+++ b/read-cache.c@@ -1754,9 +1754,8 @@ static unsigned long expand_name_field(struct strbuf *name, const char *cp_) if (name->len < len) die("malformed name field in the index"); - strbuf_remove(name, name->len - len, len); - for (ep = cp; *ep; ep++) - ; /* find the end */ + strbuf_setlen(name, name->len - len); + ep = cp + strlen((const char *)cp); strbuf_add(name, cp, ep - cp); return (const char *)ep + 1 - cp_; }
--
2.18.0.windows.1