@matheusbsbs / matheus-bagliano / commits / 288f072ec0
Fork 0

Optimize the common cases of git-read-tree

This optimizes bind_merge() and oneway_merge() to not unnecessarily remove and re-add the old index entries when they can just get replaced by updated ones. This makes these operations much faster for large trees (where "large" is in the 50,000+ file range), because we don't unnecessarily move index entries around in the index array all the time. Using the "bummer" tree (a test-tree with 100,000 files) we get: Before: [torvalds@woody bummer]$ time git commit -m"Change one file" 50/500 real 0m9.470s user 0m8.729s sys 0m0.476s After: [torvalds@woody bummer]$ time git commit -m"Change one file" 50/500 real 0m1.173s user 0m0.720s sys 0m0.452s so for large trees this is easily very noticeable indeed. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Linus Torvalds committed Aug 10, 2007 at 12:21 UTC 288f072ec033cf917eed949119428db3626ddc71
1 file changed +3 -3
unpack-trees.c
+3 -3
@@ -887,7 +887,6 @@ int bind_merge(struct cache_entry **src,
887 struct cache_entry *old = src[0];
888 struct cache_entry *a = src[1];
889
890 - remove_entry(remove);
890 if (o->merge_size != 1)
891 return error("Cannot do a bind merge of %d trees\n",
892 o->merge_size);
@@ -912,13 +911,14 @@ int oneway_merge(struct cache_entry **src,
911 struct cache_entry *old = src[0];
912 struct cache_entry *a = src[1];
913
915 - remove_entry(remove);
914 if (o->merge_size != 1)
915 return error("Cannot do a oneway merge of %d trees",
916 o->merge_size);
917
920 - if (!a)
918 + if (!a) {
919 + remove_entry(remove);
920 return deleted_entry(old, old, o);
921 + }
922 if (old && same(old, a)) {
923 if (o->reset) {
924 struct stat st;