Skip to content

Commit fc88ac6

Browse files
committed
perf(read): optimize reusable buffers and frame extraction
Separate leftover storage from reusable read chunks and add fast paths for contiguous frame extraction. Reclaim consumed leftover prefixes and avoid unnecessary read-buffer growth. Keep framing in a unified loop, cover short-read buffer reuse, and clarify that BufReader fill_buf already refills through read_buf.
1 parent 1ea9ec0 commit fc88ac6

6 files changed

Lines changed: 931 additions & 582 deletions

File tree

‎benches/README.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ By default, `FramedRead` and direct `BytesMut` use `Read::read` with initialized
1717
destinations. `FramedRead` tracks initialized spare space; direct `BytesMut`
1818
initializes its tail on each refill. With `nightly`, both use `Read::read_buf`.
1919

20+
The `BufReader::fill_buf()` comparisons use the same code in both configurations.
21+
On the tested standard library, `fill_buf()` already refills its internal buffer
22+
through the source's `Read::read_buf`; this does not depend on this crate's
23+
`nightly` feature.
24+
2025
Read compares `FramedRead`, `BufReader`, and direct `BytesMut` buffering.
2126
`FramedRead` retains partial frames separately and refills whole chunks.
2227
`decode_view()` joins crossing frames; `decode_owned()` copies the selected

‎benches/read.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
//! 500 B, 1000 B, and 1500 B respectively, including LF.
44
//! A fourth read-only workload uses Items larger than the initial buffer.
55
//! Run with `cargo bench --bench read`; add `--features nightly` on nightly
6-
//! Rust to use Read::read_buf.
6+
//! Rust to use Read::read_buf for FramedRead and direct BytesMut buffering.
7+
//! BufReader::fill_buf already uses read_buf internally on the tested std.
78
89
#![cfg_attr(feature = "nightly", feature(core_io_borrowed_buf, read_buf))]
910

0 commit comments

Comments
 (0)