Thread (11 messages) flat view 11 messages, 4 authors, 2016-06-15

Re: [PATCH 3/2] Avoid unnecessary strlen() calls

From: Shawn O. Pearce <hidden>
Date: 2016-06-15 22:43:00
Subsystem: the rest · Maintainer: Linus Torvalds

Possibly related (same subject, not in this thread)

"Shawn O. Pearce" [off-list ref] wrote:
Johannes Schindelin [off-list ref] wrote:
quoted
-- snipsnap --
[PATCH] xdiff/xutils.c(xdl_hash_record): factor out whitespace handling
...
quoted
---

	Please do not consider this patch _unless_ it is proven to enhance 
	the profile statistics substantially.
This is a massive difference for me.
...
# stock v1.5.1-rc1
$ for a in 1 2 3 4 5;do /usr/bin/time ../lt-blame blame --incremental HEAD git-gui.sh >/dev/null;done
        6.27 real         5.31 user         0.55 sys
        6.40 real         5.32 user         0.55 sys
        6.33 real         5.33 user         0.53 sys
        6.67 real         5.32 user         0.55 sys
        6.18 real         5.31 user         0.53 sys

# with the above patch
$ for a in 1 2 3 4 5;do /usr/bin/time ../js-blame blame --incremental HEAD git-gui.sh >/dev/null;done
        3.57 real         2.87 user         0.51 sys
        3.58 real         2.87 user         0.51 sys
        3.53 real         2.86 user         0.52 sys
        3.61 real         2.86 user         0.51 sys
        3.64 real         2.87 user         0.52 sys
DrNick suggested on #git to try flipping the isspace test around.
This is a smaller change and generated the same ~3.60 seconds run
as Dscho's patch.  I like DrNick's version better.  ;-)

-->8--
[PATCH] xdiff/xutils.c(xdl_hash_record): factor out whitespace handling

Since in at least one use case, xdl_hash_record() takes over 15%
of the CPU time, it makes sense to even micro-optimize it. For
many cases, no whitespace special handling is needed, and in these
cases we should not even bother to check for whitespace in _every_
iteration of the loop.

Signed-off-by: Johannes Schindelin <redacted>
Signed-off-by: Shawn O. Pearce <redacted>
---
 xdiff/xutils.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/xdiff/xutils.c b/xdiff/xutils.c
index 3653864..7b1f213 100644
--- a/xdiff/xutils.c
+++ b/xdiff/xutils.c
@@ -241,7 +241,7 @@ unsigned long xdl_hash_record(char const **data, char const *top, long flags) {
 	char const *ptr = *data;
 
 	for (; ptr < top && *ptr != '\n'; ptr++) {
-		if (isspace(*ptr) && (flags & XDF_WHITESPACE_FLAGS)) {
+		if ((flags & XDF_WHITESPACE_FLAGS) && isspace(*ptr)) {
 			const char *ptr2 = ptr;
 			while (ptr + 1 < top && isspace(ptr[1])
 					&& ptr[1] != '\n')
-- 
1.5.1.rc1.595.gd1206

-- 
Shawn.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help