Skip to content

perf: read and write large requests past the stream buffer - #87

Open
francisdb wants to merge 1 commit into
mdsteele:masterfrom
francisdb:perf/stream-direct-io
Open

perf: read and write large requests past the stream buffer#87
francisdb wants to merge 1 commit into
mdsteele:masterfrom
francisdb:perf/stream-direct-io

Conversation

@francisdb

Copy link
Copy Markdown
Contributor

Every read went through the stream's buffer, which each new Stream grew from 1 KiB up to 1 MiB (zero-filled at each step) and then copied out of, so read_to_end on a large stream cost a zero fill and two copies per byte plus the reallocations of the caller's vector.

Reads and writes of 64 KiB or more now go straight to the underlying file. read_to_end reserves the remaining length once and reads into it directly, in 16 MiB pieces. The reservation is bounded by what the stream's chain can actually hold, so a malformed file claiming an enormous length cannot make it allocate for the claim (the fuzz target caught exactly that in an earlier version).

case (criterion) before after
read from memory, 50 x 1 MiB 19.5 ms 2.2 ms
read from memory, 1 x 256 MiB 98 ms 54 ms
read from memory, 100 x 4 KiB 115 us 61 us

Tests: mixed large and small reads and writes including a large write into the middle of a stream; buffered writes visible to a following direct read; read_to_end of small and mini streams, of a stream longer than one piece, and of a stream whose entry claims about 4 GB (must fail without reserving for it).

Reads and writes of 64KiB or more go straight to the underlying file,
and read_to_end reserves the remaining length once (bounded by what the
chain can hold) instead of growing through the buffer.
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