@matheusbsbs / matheus-bagliano / commits / 8805ccac40
Fork 0

[PATCH] Avoid building object ref lists when not needed

The object parsing code builds a generic "this object references that object" because doing a full connectivity check for fsck requires it. However, nothing else really needs it, and it's quite expensive for git-rev-list that can have tons of objects in flight. So, exactly like the commit buffer save thing, add a global flag to disable it, and use it in git-rev-list. Before: $ /usr/bin/time git-rev-list --objects v2.6.12..HEAD | wc -l 12.28user 0.29system 0:12.57elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k 0inputs+0outputs (0major+26718minor)pagefaults 0swaps 59124 After this change: $ /usr/bin/time git-rev-list --objects v2.6.12..HEAD | wc -l 10.33user 0.18system 0:10.54elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k 0inputs+0outputs (0major+18509minor)pagefaults 0swaps 59124 and note how the number of pages touched by git-rev-list for this particular object list has shrunk from 26,718 (104 MB) to 18,509 (72 MB). Calculating the total object difference between two git revisions is still clearly the most expensive git operation (both in memory and CPU time), but it's now less than 40% of what it used to be. Signed-off-by: Linus Torvalds <torvalds@osdl.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Linus Torvalds committed Sep 16, 2005 at 14:55 UTC 8805ccac40348094d26b3b892c6ca3d08dc12ae0
3 files changed +12 -3
object.c
+10 -3
@@ -9,6 +9,8 @@ struct object **objs;
9 int nr_objs;
10 static int obj_allocs;
11
12 +int track_object_refs = 1;
13 +
14 static int find_object(const unsigned char *sha1)
15 {
16 int first = 0, last = nr_objs;
@@ -67,9 +69,12 @@ void created_object(const unsigned char *sha1, struct object *obj)
69
70 void add_ref(struct object *refer, struct object *target)
71 {
70 - struct object_list **pp = &refer->refs;
71 - struct object_list *p;
72 -
72 + struct object_list **pp, *p;
73 +
74 + if (!track_object_refs)
75 + return;
76 +
77 + pp = &refer->refs;
78 while ((p = *pp) != NULL) {
79 if (p->item == target)
80 return;
@@ -87,6 +92,8 @@ void mark_reachable(struct object *obj, unsigned int mask)
92 {
93 struct object_list *p = obj->refs;
94
95 + if (!track_object_refs)
96 + die("cannot do reachability with object refs turned off");
97 /* If we've been here already, don't bother */
98 if (obj->flags & mask)
99 return;
object.h
+1
@@ -17,6 +17,7 @@ struct object {
17 void *util;
18 };
19
20 +extern int track_object_refs;
21 extern int nr_objs;
22 extern struct object **objs;
23
rev-list.c
+1
@@ -581,6 +581,7 @@ int main(int argc, char **argv)
581 }
582
583 save_commit_buffer = verbose_header;
584 + track_object_refs = 0;
585
586 if (!merge_order) {
587 sort_by_date(&list);