Skip to content

Commit 22995aa

Browse files
sbauersfeldgitster
authored andcommitted
index-pack, unpack-objects: increase input buffer from 4 KiB to 128 KiB
Both index-pack and unpack-objects read pack data from stdin through a 4 KiB static buffer (input_buffer[4096]). On each fill(), consumed bytes are flushed to the output pack file via write_or_die(), so every write(2) moves at most 4 KiB. On FUSE-backed filesystems every write(2) is a synchronous round trip through the FUSE protocol (userspace -> kernel -> userspace -> back), so the 4 KiB buffer turns a clone into many unnecessary tiny writes with noticeable latency overhead. Increase the buffer from 4 KiB to 128 KiB, matching the default already used by the hashfile layer in csum-file.c. Testing with strace on HTTPS clones of git/git (~296 MB pack, 5 runs per variant, isolated builds from the same v2.54.0 source) shows: index-pack pack file writes: 72,465 -> 24,943 avg (66% reduction) total write() syscalls: 310,192 -> 259,530 avg (17% reduction) writes of exactly 4096 bytes: ~40,077 -> 0 (eliminated) All clones produce identical HEAD, file count, and pass fsck. Signed-off-by: Scott Bauersfeld <sbauersfeld@g.ucla.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 94f0577 commit 22995aa

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

builtin/index-pack.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ static int check_self_contained_and_connected;
145145

146146
static struct progress *progress;
147147

148-
/* We always read in 4kB chunks. */
149-
static unsigned char input_buffer[4096];
148+
#define INPUT_BUFFER_SIZE (128 * 1024)
149+
static unsigned char input_buffer[INPUT_BUFFER_SIZE];
150150
static unsigned int input_offset, input_len;
151151
static off_t consumed_bytes;
152152
static off_t max_input_size;

builtin/unpack-objects.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
static int dry_run, quiet, recover, has_errors, strict;
2424
static const char unpack_usage[] = "git unpack-objects [-n] [-q] [-r] [--strict]";
2525

26-
/* We always read in 4kB chunks. */
27-
static unsigned char buffer[4096];
26+
#define INPUT_BUFFER_SIZE (128 * 1024)
27+
static unsigned char buffer[INPUT_BUFFER_SIZE];
2828
static unsigned int offset, len;
2929
static off_t consumed_bytes;
3030
static off_t max_input_size;

0 commit comments

Comments
 (0)