summaryrefslogtreecommitdiff
path: root/tree.c
diff options
context:
space:
mode:
authorSergey Vlasov <vsu@altlinux.ru>2005-11-15 19:08:08 +0300
committerJunio C Hamano <junkio@cox.net>2005-11-15 11:42:29 -0800
commit4a4e6fd74f7d4564ed43eaaf59b6bd70c1959f1a (patch)
tree505862d83f5f0ffae0a2d024e7d0bfb336ddf560 /tree.c
parent545f229a4b43212e683ac63e5aa740324ac7799e (diff)
downloadgit-4a4e6fd74f7d4564ed43eaaf59b6bd70c1959f1a.tar.gz
Rework object refs tracking to reduce memory usage
Store pointers to referenced objects in a variable sized array instead of linked list. This cuts down memory usage of utilities which use object references; e.g., git-fsck-objects --full on the git.git repository consumes about 2 MB of memory tracked by Massif instead of 7 MB before the change. Object refs are still the biggest consumer of memory (57%), but the malloc overhead for a single block instead of a linked list is substantially smaller. Signed-off-by: Sergey Vlasov <vsu@altlinux.ru> Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'tree.c')
-rw-r--r--tree.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/tree.c b/tree.c
index 315b6a5d1c..8b42a07b20 100644
--- a/tree.c
+++ b/tree.c
@@ -148,6 +148,7 @@ int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size)
{
void *bufptr = buffer;
struct tree_entry_list **list_p;
+ int n_refs = 0;
if (item->object.parsed)
return 0;
@@ -184,11 +185,21 @@ int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size)
obj = &entry->item.blob->object;
}
if (obj)
- add_ref(&item->object, obj);
+ n_refs++;
entry->parent = NULL; /* needs to be filled by the user */
*list_p = entry;
list_p = &entry->next;
}
+
+ if (track_object_refs) {
+ struct tree_entry_list *entry;
+ unsigned i = 0;
+ struct object_refs *refs = alloc_object_refs(n_refs);
+ for (entry = item->entries; entry; entry = entry->next)
+ refs->ref[i++] = entry->item.any;
+ set_object_refs(&item->object, refs);
+ }
+
return 0;
}