Skip to content

Commit

Permalink
[PATCH] Avoid building object ref lists when not needed
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Linus Torvalds authored and Junio C Hamano committed Sep 16, 2005
1 parent b0d8923 commit 8805cca
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
13 changes: 10 additions & 3 deletions object.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ struct object **objs;
int nr_objs;
static int obj_allocs;

int track_object_refs = 1;

static int find_object(const unsigned char *sha1)
{
int first = 0, last = nr_objs;
Expand Down Expand Up @@ -67,9 +69,12 @@ void created_object(const unsigned char *sha1, struct object *obj)

void add_ref(struct object *refer, struct object *target)
{
struct object_list **pp = &refer->refs;
struct object_list *p;

struct object_list **pp, *p;

if (!track_object_refs)
return;

pp = &refer->refs;
while ((p = *pp) != NULL) {
if (p->item == target)
return;
Expand All @@ -87,6 +92,8 @@ void mark_reachable(struct object *obj, unsigned int mask)
{
struct object_list *p = obj->refs;

if (!track_object_refs)
die("cannot do reachability with object refs turned off");
/* If we've been here already, don't bother */
if (obj->flags & mask)
return;
Expand Down
1 change: 1 addition & 0 deletions object.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ struct object {
void *util;
};

extern int track_object_refs;
extern int nr_objs;
extern struct object **objs;

Expand Down
1 change: 1 addition & 0 deletions rev-list.c
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,7 @@ int main(int argc, char **argv)
}

save_commit_buffer = verbose_header;
track_object_refs = 0;

if (!merge_order) {
sort_by_date(&list);
Expand Down

0 comments on commit 8805cca

Please sign in to comment.