Skip to content

bench: reuse the buffers across iterations - #95

Open
francisdb wants to merge 3 commits into
mdsteele:masterfrom
francisdb:bench/reuse-buffers
Open

bench: reuse the buffers across iterations#95
francisdb wants to merge 3 commits into
mdsteele:masterfrom
francisdb:bench/reuse-buffers

Conversation

@francisdb

@francisdb francisdb commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Builds on #94 (its commit is included here until it merges).

Every iteration wrote into, or read into, a freshly allocated Vec. For the large sizes the kernel mapping that memory costs several times the copy itself, so those rows measured "fill a new buffer" more than the crate: on my machine a 256 MiB copy into a fresh Vec takes 57 ms against 11 ms into a resident one.

Each case now creates its file buffer, source data and read sink once and reuses them, cleared rather than freed, across iterations. The disk write group still creates a fresh temp file per iteration, since that is part of writing to disk.

bench before after
write to memory, 1 x 256 MiB 71 ms 18 ms
write to memory, 50 x 1 MiB 9.6 ms 2.7 ms
read from memory, 1 x 256 MiB 57 ms 22 ms

The small cases are unchanged.

The second commit replaces the 50 x 1 MiB case with 256 x 1 MiB, so that row carries the same bytes as the single 256 MiB stream and the two read directly against each other. With the reused buffers: write to memory 14 ms against 18 ms, read from memory 12 ms against 22 ms, write to disk 116 ms against 106 ms. The many-stream side wins in memory because 1 MiB buffers stay in cache; the single stream wins on disk because each extra stream costs a directory entry and its FAT links.

The read benches only covered memory, which hides the per-call cost of
an unbuffered File. Add a disk read group with a short measurement
window.
Every iteration wrote into, or read into, a freshly allocated Vec, and
for the large sizes the kernel mapping that memory cost several times
the copy itself. Create the file buffer, the source data and the read
sink once per case so the numbers cover the crate.
The two rows then read directly against each other: what separates them
is the per-stream overhead and the cache behaviour of 1 MiB buffers.
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