Skip to content

perf: read the DIFAT, FAT and MiniFAT in whole sectors on open - #96

Merged
mdsteele merged 2 commits into
mdsteele:masterfrom
francisdb:perf/read-fat-sectors-at-once
Sep 20, 2026
Merged

mdsteele merged 2 commits into
mdsteele:masterfrom
francisdb:perf/read-fat-sectors-at-once

Conversation

@francisdb

Copy link
Copy Markdown
Contributor

Opening a file reads the DIFAT, FAT and MiniFAT one 4 byte entry at a time, and for the MiniFAT with a seek before every entry. On an unbuffered File that is one or two syscalls per entry: opening a 100 MB file took 42k reads and 15k seeks before any stream was touched. This is most noticeable on network shares and when opening many files.

Each DIFAT and FAT sector, and the whole MiniFAT chain, is now read into a buffer and the entries are decoded from memory. The same bytes are read as before, only in fewer calls. The extra memory is one sector buffer, plus a temporary copy of the MiniFAT while it is decoded.

The first commit adds an open_disk bench group, since the existing disk benches mix the open with the stream reads. Results against that baseline:

case before after
n=10000, size=0B 3.64 ms 3.53 ms
n=1000, size=64B 650 µs 379 µs
n=100, size=4KiB-1 (MiniFAT) 1.41 ms 113 µs
n=100, size=4KiB (FAT) 154 µs 44.5 µs
n=256, size=1MiB 8.27 ms 923 µs
n=1, size=256MiB 8.14 ms 824 µs

read_streams_disk improves 17 to 86% as it includes the open. The rest of the bench suite is unchanged.

Opening loads the DIFAT, FAT, directory and MiniFAT. The existing disk benches include it, but mixed with the stream reads.
Opening a file read these tables one 4 byte entry at a time, and for the
MiniFAT with a seek before every entry. On an unbuffered File that is one
or two syscalls per entry: opening a 100 MB file took 42k reads and 15k
seeks before any stream was touched.

Read each DIFAT and FAT sector, and the whole MiniFAT chain, into a
buffer and decode the entries from memory. The open_disk bench is 70 to
92% faster for the cases that have a FAT or MiniFAT of any size.
@mdsteele
mdsteele merged commit 9b4e647 into mdsteele:master Sep 20, 2026
4 checks passed
@francisdb
francisdb deleted the perf/read-fat-sectors-at-once branch September 20, 2026 19:23
@francisdb

Copy link
Copy Markdown
Contributor Author

That was quick, thanks @mdsteele

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.

2 participants