reftable/record: store "val2" hashes as static arrays
Similar to the preceding commit, convert ref records of type "val2" to store their object IDs in static arrays instead of allocating them for every single record. We're using the same benchmark as in the preceding commit, with `git show-ref --quiet` in a repository with ~350k refs. This time around though the effects aren't this huge. Before: HEAP SUMMARY: in use at exit: 21,163 bytes in 193 blocks total heap usage: 1,419,040 allocs, 1,418,847 frees, 62,153,868 bytes allocated After: HEAP SUMMARY: in use at exit: 21,163 bytes in 193 blocks total heap usage: 1,410,148 allocs, 1,409,955 frees, 61,976,068 bytes allocated This is because "val2"-type records are typically only stored for peeled tags, and the number of annotated tags in the benchmark repository is rather low. Still, it can be seen that this change leads to a reduction of allocations overall, even if only a small one. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
7af607c58d
commit
b31e3cc620
@ -222,9 +222,7 @@ static void reftable_ref_record_copy_from(void *rec, const void *src_rec,
|
||||
memcpy(ref->value.val1, src->value.val1, hash_size);
|
||||
break;
|
||||
case REFTABLE_REF_VAL2:
|
||||
ref->value.val2.value = reftable_malloc(hash_size);
|
||||
memcpy(ref->value.val2.value, src->value.val2.value, hash_size);
|
||||
ref->value.val2.target_value = reftable_malloc(hash_size);
|
||||
memcpy(ref->value.val2.target_value,
|
||||
src->value.val2.target_value, hash_size);
|
||||
break;
|
||||
@ -298,8 +296,6 @@ void reftable_ref_record_release(struct reftable_ref_record *ref)
|
||||
reftable_free(ref->value.symref);
|
||||
break;
|
||||
case REFTABLE_REF_VAL2:
|
||||
reftable_free(ref->value.val2.target_value);
|
||||
reftable_free(ref->value.val2.value);
|
||||
break;
|
||||
case REFTABLE_REF_VAL1:
|
||||
break;
|
||||
@ -401,11 +397,9 @@ static int reftable_ref_record_decode(void *rec, struct strbuf key,
|
||||
return -1;
|
||||
}
|
||||
|
||||
r->value.val2.value = reftable_malloc(hash_size);
|
||||
memcpy(r->value.val2.value, in.buf, hash_size);
|
||||
string_view_consume(&in, hash_size);
|
||||
|
||||
r->value.val2.target_value = reftable_malloc(hash_size);
|
||||
memcpy(r->value.val2.target_value, in.buf, hash_size);
|
||||
string_view_consume(&in, hash_size);
|
||||
break;
|
||||
|
Reference in New Issue
Block a user