From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH] read-cache: avoid memcpy in expand_name_field in index v4
Date: Mon, 18 Mar 2013 19:58:02 +0700 [thread overview]
Message-ID: <1363611482-1015-1-git-send-email-pclouds@gmail.com> (raw)
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 reply other threads:[~2013-03-18 12:58 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-18 12:58 Nguyễn Thái Ngọc Duy [this message]
2013-03-18 17:50 ` [PATCH] read-cache: avoid memcpy in expand_name_field in index v4 Junio C Hamano
2013-03-19 1:29 ` Duy Nguyen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1363611482-1015-1-git-send-email-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.