Speed up macOS directory scans when bulk reads stall - #401
Merged
Conversation
Byron
force-pushed
the
faster-bulk-traversal
branch
2 times, most recently
from
September 11, 2026 13:41
f27ef37 to
521a07a
Compare
Byron
marked this pull request as ready for review
September 11, 2026 13:43
This was an issue I encountered on APFS, a directory created by rustc with more than 1m files in it. In that case, bulk reading is slow (while efficient), and it turned out to be better to detect this and switch over to stat-based traversal. While looking at the filesystem probing code more closely (and how it's not dependent on CPU performance by differntiating wall time from kernel time), I basically rubber-stamped all the other code. Too much to look at, too foreign by now. But it did look cleaned up, so 👍. <!-- agent --> The reported target-directory scan left one worker waiting inside `getattrlistbulk` at about 15% of a CPU core. Native directory collection also held an entire parent directory before publishing entries and child jobs. Probe at most two initial bulk buffers before publishing them. Compare calling-thread user and kernel CPU time with elapsed time, and select the existing parallel stat queue when both refills spend more time waiting than executing. Reopen through ordinary enumeration only after that decision, discarding the unpublished probe to avoid mixed cursors or duplicate entries. Keep bulk reads when the probe is CPU-bound. The initial probe deliberately does not adapt to later cache changes. Share streaming native traversal between ordering modes, preserve parent ordering and APFS metadata, and bound queued metadata jobs by processing new batches inline when the queue fills. Regression coverage checks scale-independent timing decisions, bounded probing and metadata backlogs, streamed child jobs, parent ordering, and stat/native parity for clones, resource forks, hard links and symlinks. The timing test failed against the provisional fixed latency policy; the queue-bound test failed without backpressure. Assisted-by: GPT 6.0 Co-authored-by: GPT 6.0 <codex@openai.com>
Byron
force-pushed
the
faster-bulk-traversal
branch
from
September 11, 2026 13:44
521a07a to
249bdf3
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Tasks
This section is for Byron only. Models continuing this PR must not add, remove, check, uncheck, rename, or reorder checkboxes here.
Everything below this line was generated by
Codex GPT-6.Created by Codex on behalf of Byron. Byron will review before this is ready to merge.
Change
Large macOS directories could leave one worker waiting inside
getattrlistbulkat about 15% of a CPU core. Native traversal also collected an entire parent directory before publishing its entries and child jobs.Native traversal now streams batches and uses a bounded initial bulk probe to choose how to collect metadata. If the first refill is CPU-bound, bulk enumeration continues with its cached metadata. If two initial refills each spend more time waiting than executing, multiworker walks reopen with ordinary directory enumeration and distribute stat calls through the existing worker pool. The CPU measurement includes kernel time; there is no absolute latency or entry-count cutoff.
The probe holds at most two 64 KiB bulk buffers worth of entries and is discarded only after reopening succeeds, before any entry or child job has been published. This avoids duplicate entries and mixing incompatible directory cursors. Metadata queues are bounded; a full local queue makes the producer process its next batch inline. Parent ordering and optional APFS clone metadata remain supported.
This initial decision deliberately trades continuous adaptation for bounded state: it can miss a later cache transition, and a temporary cold prefix can select stat even if later bulk reads would be fast. CPU waiting also includes descheduling, so the signal is a heuristic rather than a universal crossover guarantee.
Measurements
On the reported live target, alternating final/original/final interactive runs took 18.05 / 34.60 / 17.63 seconds. The final run averaged about 1.24 CPU cores, versus 0.29 for the original whole scan; peak memory fell from 404 MB to 205 MB. The target was changing during investigation, so these timings are not a controlled benchmark ratio.
A stable 218,432-file corpus retained cached performance: three alternating cached runs had medians of 0.402 s original and 0.399 s final. Isolated cached bulk refills used about 99.5–99.8% CPU, while the slow real directory used about 14%, supporting a relative waiting/execution signal. Restricting bulk calls to listing attributes still spent 40.2 of 43.2 seconds inside listing calls, which is why the implementation reopens with ordinary enumeration after the unpublished probe.
Validation
make check,make unit-tests, andmake journey-tests.cargo clippy --workspace --all-targets --all-features -- -D warningsandcargo fmt --check.Reported issue