git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] read-cache: avoid memcpy in expand_name_field in index v4

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Mar 18, 2013, 12:58 UTC
Message-ID
<1363611482-1015-1-git-send-email-pclouds@gmail.com>

perf reports memcpy at the the 6th position [1] in "git status -uno" using index v4, and strbuf_remove() in expand_name_field() accounts for 25% of that. What we need here is a simple string cut and a cheaper strbuf_setlen() should be enough. After this change, memcpy drops down to the 13th position [2] and is dominated by read_index_from.

[1] before
+     15.74%   git  git                [.] blk_SHA1_Block
+     13.22%   git  [kernel.kallsyms]  [k] link_path_walk
+     10.91%   git  [kernel.kallsyms]  [k] __d_lookup
+      8.17%   git  [kernel.kallsyms]  [k] strncpy_from_user
+      4.75%   git  [kernel.kallsyms]  [k] memcmp
+      2.42%   git  libc-2.11.2.so     [.] memcpy
[2] after
+     16.30%   git  git                [.] blk_SHA1_Block
+     13.43%   git  [kernel.kallsyms]  [k] link_path_walk
+     11.45%   git  [kernel.kallsyms]  [k] __d_lookup
+      8.73%   git  [kernel.kallsyms]  [k] strncpy_from_user
+      5.14%   git  [kernel.kallsyms]  [k] memcmp
+      2.29%   git  [kernel.kallsyms]  [k] do_lookup
+      2.21%   git  libc-2.11.2.so     [.] 0x6daf6
+      1.98%   git  [kernel.kallsyms]  [k] _atomic_dec_and_lock
+      1.98%   git  [kernel.kallsyms]  [k] _raw_spin_lock
+      1.86%   git  [kernel.kallsyms]  [k] acl_permission_check
+      1.61%   git  [kernel.kallsyms]  [k] kmem_cache_free
+      1.59%   git  git                [.] unpack_trees
+      1.47%   git  libc-2.11.2.so     [.] memcpy
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 I was after something else when I noticed this. Seems like a simple
 and safe change.
 read-cache.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/read-cache.c b/read-cache.c
index 827ae55..8c443aa 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -1354,7 +1354,7 @@ 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);
+	strbuf_setlen(name, name->len - len);
 	for (ep = cp; *ep; ep++)
 		; /* find the end */
 	strbuf_add(name, cp, ep - cp);
-- 
1.8.2.83.gc99314b
Next: Junio C Hamano
Message 1 of 3 in “read-cache: avoid memcpy in expand_name_field in index v4”
  1. read-cache: avoid memcpy in expand_name_field in index v4Nguyễn Thái Ngọc Duy, Mar 18, 2013
  2. Junio C HamanoMar 18, 2013
  3. Duy NguyenMar 19, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.