• Show log

    Commit

  • Hash : 8cc16e29
    Author : Kirill A. Shutemov
    Date : 2011-06-30T23:22:42

    index: speedup git_index_append()/git_index_append2()
    
    git_index_find() in index_insert() is useless if replace is not
    requested (append). Do not call it in this case.
    It speedup git_index_append() *dramatically* on large indexes.
    
    $ cat index_test.c
    
    int main(int argc, char **argv)
    {
            git_index *index;
            git_repository *repo;
            git_odb *odb;
            struct git_index_entry entry;
            git_oid tree_oid;
            char tree_hex[41];
            int i;
    
            git_repository_init(&repo, "/tmp/myrepo", 0);
            odb = git_repository_database(repo);
            git_repository_index(&index, repo);
    
            memset(&entry, 0, sizeof(entry));
            git_odb_write(&entry.oid, odb, "", 0, GIT_OBJ_BLOB);
            entry.path = "test.file";
    
            for (i = 0; i < 50000; i++)
                    git_index_append2(index, &entry);
    
            git_tree_create_fromindex(&tree_oid, index);
            git_oid_fmt(tree_hex, &tree_oid);
            tree_hex[40] = '\0';
            printf("tree: %s\n", tree_hex);
    
            git_index_free(index);
            git_repository_free(repo);
    
            return 0;
    }
    
    Before:
    $ time ./index_test
    tree: 43f73659c43b651588cc81459d9e25b08721b95d
    ./index_test  151.19s user 0.05s system 99% cpu 2:31.78 total
    
    After:
    $ time ./index_test
    tree: 43f73659c43b651588cc81459d9e25b08721b95d
    ./index_test  0.05s user 0.00s system 94% cpu 0.059 total
    
    About 2573 times speedup on this test :)
    
    Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>