perf: check should_interrupt per entry in index_as_worktree#2631
Merged
Sebastian Thiel (Byron) merged 1 commit intoMay 31, 2026
Merged
Conversation
The interrupt flag was only checked at chunk boundaries (~500 entries, 'just like git'), so an in-flight chunk ran to completion even after interruption was requested. Check it per entry instead. This makes an interrupted status responsive instead of waiting up to a chunk, and in particular lets the background index-vs-worktree scan that Repository::is_dirty() leaves running (after it early-returns on the first change) wind down promptly. On a 50k-file repo with a dirty worktree, a tight is_dirty() loop drops from ~49ms to ~35ms by not letting those background scans pile up. The added cost is one Relaxed atomic load per entry; clean and uninterrupted scans are unaffected (measured within noise). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sebastian Thiel (Byron)
approved these changes
May 31, 2026
Member
Sebastian Thiel (Byron)
left a comment
There was a problem hiding this comment.
Thanks a lot, great catch!
19e4330
into
GitoxideLabs:main
78 of 84 checks passed
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.
index_as_worktreeonly checked the interrupt flag at chunk boundaries, so an in-flight chunk ran to completion even after interruption was requested. This checks it per entry instead.I was looking at
Repository::is_dirty(), trying to determine if #1180 was closeable, as it requested a perf improvement on this function. A larger improvement would require batched directory-stat caching as discussed in #2296, or to consumeUNTRandFSMNtokens as attempted in #2503.is_dirty()now early-returns on the first change and drops the status iterator, which sets the interrupt flag and leaves a detached background scan to wind down on its own. With the per-chunk check that background scan kept stat-ing its entire chunk; now it stops at the next entry.I benchmarked it on a 50k-file repo:
The performance win shows up when
is_dirty()is hit repeatedly and the leaked background scans would otherwise pile up; it scales with repo size and is within noise below ~10k files.🤖 Generated with Claude Code