Skip to content

perf: reuse a chain's sector list across opens instead of rewalking the FAT - #89

Open
francisdb wants to merge 2 commits into
mdsteele:masterfrom
francisdb:perf/chain-cache
Open

perf: reuse a chain's sector list across opens instead of rewalking the FAT#89
francisdb wants to merge 2 commits into
mdsteele:masterfrom
francisdb:perf/chain-cache

Conversation

@francisdb

@francisdb francisdb commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Fixes the remaining cause of #57.

A Stream opens its chain anew for every buffer refill, and Chain::new walks the whole FAT chain each time, so reading a long stream costs O(n^2) in its sector count. #79 hid most of it with the 1 MiB buffer, but each refill of a 1 GiB stream still walked 262144 FAT entries.

The allocator now keeps the sector list of the last dropped Chain and hands it to the next open of the same start sector; any set_fat discards it. Chain keeps its list in step on shrink and free so the list handed back always matches the FAT. Same idea as #81, applied to any chain.

New benches, one 256 MiB stream in memory:

Bench master this PR
copy 256 MiB (io::copy) 40.6 ms 15.5 ms
1000 x seek + read 16 B 142 ms 48 ms

The #57 scenario (1 GiB stream, copy the first 50 MiB): 34 ms on 0.14.0, 14 ms here.

…he FAT

A stream opens its chain anew for every buffer refill, and Chain::new
walks the whole FAT chain each time, so reading or writing a long stream
costs O(n^2) in its sector count. The allocator now keeps the sector list
of the last dropped chain and hands it to the next open of the same start
sector; any FAT change discards it.
The existing read benches read each stream with a single read_to_end.
Add a full io::copy of a 256 MiB stream and a thousand seek-and-read
pairs over it, the two access patterns that refill the stream buffer
most often.
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