Skip to content

db/etl: stop the bufio read benchmarks allocating per field - #23618

Closed
AskAlexSharov wants to merge 1 commit into
mainfrom
alex/etl_bench_lenbuf_37
Closed

db/etl: stop the bufio read benchmarks allocating per field#23618
AskAlexSharov wants to merge 1 commit into
mainfrom
alex/etl_bench_lenbuf_37

Conversation

@AskAlexSharov

Copy link
Copy Markdown
Collaborator

readFieldBufioU16 and readFieldBufioU32 read the length prefix into a local [2]byte/[4]byte and pass it to io.ReadFull. That takes an io.Reader, so the array escapes and every field read costs an allocation.

The mmap readers beside them slice the mapping directly and pay nothing, so the comparison this file exists to make was handing the bufio side a penalty that has nothing to do with buffered I/O.

The caller owns lenBuf now. BenchmarkSequentialRead/val32/bufio_u16, two alternating rounds each:

ns/op B/op allocs/op
before 57.3M, 59.5M 8.42MB 3947589
after 42.8M, 42.0M 525KB 7

Benchmark-only; no production code touched. Found while auditing allocations for #23599.

readFieldBufioU16 and U32 read the length prefix into a local array and
hand it to io.ReadFull, which takes an io.Reader - so the array escapes
and every field read costs an allocation. The mmap readers next to them
slice the mapping directly and pay nothing, so the comparison the file
exists to make was handing the bufio side a penalty that is not about
buffered I/O at all.

The caller owns lenBuf now. BenchmarkSequentialRead/val32/bufio_u16, two
alternating rounds each: 57.3ms and 59.5ms before, 42.8ms and 42.0ms
after - 8.4MB over 3947589 allocations becomes 525KB over 7.
@AskAlexSharov
AskAlexSharov deleted the alex/etl_bench_lenbuf_37 branch August 27, 2026 06:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant