Repository navigation
fix: hand loaded files to the screen without sleep-polling - #5
Merged
Merged
Conversation
The input worker published each file through a two-slot channel and slept 5 ms whenever it was full, while the screen took the two files and waited for the next wake. On a busy machine, loading the Linux v6.0..v7.0 patch spent most of its time asleep: about 30 s to reach all files against a 5 s parse. Files now go through a queue bounded by 1,024 files or 8 MiB of index bytes. When the queue is full, the parser blocks on a condition variable until the screen drains it. The screen takes everything queued on each wake. Prepared sources stay limited to two, because each holds both complete sides. Closing the worker wakes a blocked parser.
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.
Problem
Loading the full Linux v6.0→v7.0 patch (76,872 files, 711 MB, SHA-256
510693d1…perfixtures/diffshub/corpus.json) took 12–44 s to reach all files. Parse alone (inspect --summary) takes about 5 s. Asampleduring loading showed the parser thread asleep about 90% of the time.The cause was the handoff in
src/input/worker.rs. Each file went through async_channel(2), and the parser slept 5 ms whenever the channel was full. The screen loop took the two files and then waited for the next wake. On a busy machine, loading time was set by thread wake-up latency, not by parsing.Change
src/input/worker.rs: replaces the reply channel with a mailbox (Mutex<VecDeque>+Condvar).close()marks the mailbox closed, which wakes a blocked parser withCancelled, and drops the queued replies.try_replykeeps its behavior:Disconnectedstill means the worker exited and nothing remains.try_repliestakes every queued reply at once.src/engine.rs:polltakes every queued input reply on each wake, instead of up to 64 replies from a queue that held only 2. The queue bound now limits how much work one turn does, so a keypress is still handled after each turn.The intent of the bounded queue is unchanged (LARGE_DIFFS.md §6 and DELIVERY_REPORT): published files are bounded, and backpressure pauses ingestion, not keyboard input. Queued files are the same
Arc<FileIndex>that the document keeps, so the larger bound adds no measurable peak memory (see below).Measurements
The A/B runs were interleaved on the same machine (macOS, 18 cores, shared and busy: load average 13–17, with unrelated long-running processes). There were 6 runs per arm and both binaries were warmed first. Each run is a real 160×50 PTY using the repository's
tools/terminal_baseline.Session/Frames.corpus_acceptancecriterion.?during loading and measures the time until a frame shows the change.5856855The first-text difference is within noise. One branch run took 22 ms, and the other five took 7.0–13.6 ms.
Parse baseline (
tools/parse_baseline.py, branch binary): all 5 fixtures exit 0 and their git totals match. Linux takes 4.74 s with a 386 MiB peak. With this change, interactive loading is close to the parse time.Checks
cargo fmt --checkcargo clippy --all-targets(default and--all-features), andcargo clippy --lib --no-default-features, all with-D warningscargo test --release --locked --no-fail-fast -- --test-threads=1Tests:
tests/input_worker.rstests assumed the two-file queue. They now assert that all files queue without the screen draining, and they still check that published sources remain valid and are released after close.