D2627: xdiff: use memchr instead of character scanning

2018-03-03 Thread quark (Jun Wu)
quark added a comment.


  It seems `mdiff.textdiff` used by `perfbdiff` won't actually use xdiff. Maybe 
`perfunidiff --config experimental.xdiff=1` should be used instead?

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D2627

To: indygreg, #hg-reviewers, quark
Cc: mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D2627: xdiff: use memchr instead of character scanning

2018-03-03 Thread indygreg (Gregory Szorc)
indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  Compilers (at least in the configuration used to build Mercurial)
  don't seem to be able to optimize a loop to look for a byte in a
  buffer very well.
  
  After removing hashing from the loop in our previous commit, we
  no longer have a good reason to use a loop at all: we can instead
  use memchr() to find a byte value in a memory range. memchr() will
  often be backed by platform-optimal, hand-written assembly that will
  perform better than anything a compiler can emit.
  
  Using memchr() to scan for newlines makes xdiff a bit faster. On
  the mozilla-central repository:
  
$ hg perfbdiff --alldata -c --count 10 --blocks --xdiff 40
! wall 0.796796 comb 0.79 user 0.79 sys 0.00 (best of 13)
! wall 0.589753 comb 0.59 user 0.59 sys 0.00 (best of 17)

$ hg perfbdiff -m --count 100 --blocks --xdiff 40
! wall 9.450092 comb 9.46 user 8.47 sys 0.99 (best of 3)
! wall 7.364899 comb 7.36 user 6.43 sys 0.93 (best of 3)

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D2627

AFFECTED FILES
  mercurial/thirdparty/xdiff/xutils.c

CHANGE DETAILS

diff --git a/mercurial/thirdparty/xdiff/xutils.c 
b/mercurial/thirdparty/xdiff/xutils.c
--- a/mercurial/thirdparty/xdiff/xutils.c
+++ b/mercurial/thirdparty/xdiff/xutils.c
@@ -303,12 +303,16 @@
 
 unsigned long xdl_hash_record(char const **data, char const *top, long flags) {
XXH32_hash_t h;
-   char const *ptr = *data;
+   char const *ptr;
 
if (flags & XDF_WHITESPACE_FLAGS)
return xdl_hash_record_with_whitespace(data, top, flags);
 
-   for (; ptr < top && *ptr != '\n'; ptr++) { }
+   ptr = memchr(*data, '\n', top - *data + 1);
+   if (!ptr) {
+   ptr = top;
+   }
+
h = XDIFF_XXH32(*data, ptr - *data + 1, 0);
*data = ptr < top ? ptr + 1: ptr;
return h;



To: indygreg, #hg-reviewers
Cc: mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel