db/etl: stop the bufio read benchmarks allocating per field - #23618
Closed
AskAlexSharov wants to merge 1 commit into
Closed
db/etl: stop the bufio read benchmarks allocating per field#23618AskAlexSharov wants to merge 1 commit into
AskAlexSharov wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
readFieldBufioU16andreadFieldBufioU32read the length prefix into a local[2]byte/[4]byteand pass it toio.ReadFull. That takes anio.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
lenBufnow.BenchmarkSequentialRead/val32/bufio_u16, two alternating rounds each:Benchmark-only; no production code touched. Found while auditing allocations for #23599.