read-cache: avoid allocating every ondisk entry when writing
commitce012deb98650b5b7bba58d534fed27628e34234
authorKevin Willford <kewillf@microsoft.com>
Mon, 21 Aug 2017 21:24:32 +0000 (21 15:24 -0600)
committerJunio C Hamano <gitster@pobox.com>
Mon, 21 Aug 2017 23:02:59 +0000 (21 16:02 -0700)
tree82c4ad3e177740cdcb0d941891b93ac5eaa917da
parentb50386c7c038ccea8f70d2a66ac78f189240ef05
read-cache: avoid allocating every ondisk entry when writing

When writing the index for each entry an ondisk struct will be
allocated and freed in ce_write_entry.  We can do better by
using a ondisk struct on the stack for each entry.

This is accomplished by using a stack ondisk_cache_entry_extended
outside looping through the entries in do_write_index.  Only the
fixed fields of this struct are used when writing and depending on
whether it is extended or not the flags2 field will be written.
The name field is not used and instead the cache_entry name field
is used directly when writing out the name.  Because ce_write is
using a buffer and memcpy to fill the buffer before flushing to disk,
we don't have to worry about doing multiple ce_write calls.

Running the p0007-write-cache.sh tests would save anywhere
between 3-7% when the index had over a million entries with no
performance degradation on small repos.

Signed-off-by: Kevin Willford <kewillf@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
read-cache.c