Skip to content

perf: check should_interrupt per entry in index_as_worktree#2631

Merged
Sebastian Thiel (Byron) merged 1 commit into
GitoxideLabs:mainfrom
sharifhsn:perf/is-dirty-fast-path
May 31, 2026
Merged

perf: check should_interrupt per entry in index_as_worktree#2631
Sebastian Thiel (Byron) merged 1 commit into
GitoxideLabs:mainfrom
sharifhsn:perf/is-dirty-fast-path

Conversation

@sharifhsn
Copy link
Copy Markdown
Contributor

index_as_worktree only 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 consume UNTR and FSMN tokens 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:

main this PR
clean 61.3 ms 61.8 ms
dirty, change in first-scanned file 49.4 ms 34.7 ms
dirty, change in last-scanned file 61.5 ms 61.4 ms

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

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>
Copilot AI review requested due to automatic review settings May 30, 2026 20:25
Copy link
Copy Markdown
Member

@Byron Sebastian Thiel (Byron) left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot, great catch!

@Byron Sebastian Thiel (Byron) merged commit 19e4330 into GitoxideLabs:main May 31, 2026
78 of 84 checks passed
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