quark requested changes to this revision.
quark added a comment.
This revision now requires changes to proceed.


  It seems xxhash can make things slower if the line is short.
  
    ## test case
    open('a','w').write(''.join('%s\n' % (i % 100000) for i in 
xrange(10000000)))
    open('b','w').write(''.join('%s\n' % (i % 100000) for i in 
xrange(10000001)))
  
  
  
    ## before xxhash
    ./xdiff /tmp/[ab] &> /dev/null  0.67s user 0.21s system 99% cpu 0.875 total
    ## after xxhash
    ./xdiff /tmp/[ab] &> /dev/null  2.86s user 0.43s system 98% cpu 3.315 total
  
  The memchr change does not change much - it's still about 3 seconds on my 
machine.
  
  Code I use for testing:
  
    // contrib/xdiff/xdiff.c
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <unistd.h>
    
    #include "mercurial/thirdparty/xdiff/xdiff.h"
    
    #define abort(...)                                                          
   \
        {                                                                      \
                fprintf(stderr, __VA_ARGS__);                                  \
                exit(-1);                                                      \
        }
    
    char buf[4096000];
    void readfile(const char *path, mmfile_t *file)
    {
        memset(file, 0, sizeof(*file));
        FILE *fp = fopen(path, "r");
        if (!fp) {
                abort("cannot open %s\n", path);
        }
        while (!feof(fp)) {
                size_t size = fread(buf, 1, sizeof buf, fp);
                if (size > 0) {
                        size_t new_size = file->size + size;
                        file->ptr = realloc(file->ptr, new_size);
                        if (!file->ptr) {
                                abort("cannot allocate\n");
                        }
                        memcpy(file->ptr + file->size, buf, size);
                        file->size = new_size;
                }
        }
        fclose(fp);
    }
    
    static int xdiff_outf(void *priv_, mmbuffer_t *mb, int nbuf)
    {
        int i;
        for (i = 0; i < nbuf; i++) {
                write(STDOUT_FILENO, mb[i].ptr, mb[i].size);
        }
        return 0;
    }
    
    int main(int argc, char const *argv[])
    {
        if (argc < 3) {
                abort("usage: %s FILE1 FILE2\n", argv[0]);
        }
    
        mmfile_t a, b;
    
        readfile(argv[1], &a);
        readfile(argv[2], &b);
    
        xpparam_t xpp = {
            0,    /* flags */
            NULL, /* anchors */
            0,    /* anchors_nr */
        };
        xdemitconf_t xecfg = {
            3,    /* ctxlen */
            0,    /* interhunkctxlen */
            0,    /* flags */
            NULL, /* find_func */
            NULL, /* find_func_priv */
            NULL, /* hunk_consume_func */
        };
        xdemitcb_t ecb = {
            0,           /* priv */
            &xdiff_outf, /* outf */
        };
    
        xdl_diff(&a, &b, &xpp, &xecfg, &ecb);
    
        free(a.ptr);
        free(b.ptr);
    
        return 0;
    }
  
  
  
    ## contrib/xdiff/Makefile
    xdiff: ../../mercurial/thirdparty/xdiff/*.c xdiff.c
        gcc -O2 -g -std=c99 -I../.. -I../../mercurial/thirdparty/xdiff 
-I../../mercurial -o $@ $^
    
    clean:
        -rm -f xdiff

REPOSITORY
  rHG Mercurial

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

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

Reply via email to