reftable/block: reuse compressed array

Similar to the preceding commit, let's reuse the `compressed` array that
we use to store compressed data in. This results in a small reduction in
memory allocations when writing many refs.

Before:

  HEAP SUMMARY:
      in use at exit: 671,931 bytes in 151 blocks
    total heap usage: 22,620,528 allocs, 22,620,377 frees, 1,245,549,984 bytes allocated

After:

  HEAP SUMMARY:
      in use at exit: 671,931 bytes in 151 blocks
    total heap usage: 22,618,257 allocs, 22,618,106 frees, 1,236,351,528 bytes allocated

So while the reduction in allocations isn't really all that big, it's a
low hanging fruit and thus there isn't much of a reason not to pick it.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Patrick Steinhardt
2024-04-08 14:24:40 +02:00
committed by Junio C Hamano
parent a155ab2bf4
commit fa74f32291
2 changed files with 8 additions and 9 deletions

View File

@@ -19,6 +19,9 @@ https://developers.google.com/open-source/licenses/bsd
*/
struct block_writer {
z_stream *zstream;
unsigned char *compressed;
size_t compressed_cap;
uint8_t *buf;
uint32_t block_size;