Skip to content

Fix the index being read twice over for a write GitX made itself - #602

Merged
hannesa2 merged 1 commit into
gitx:masterfrom
goneng:fix-self-inflicted-index-refresh
Sep 13, 2026
Merged

hannesa2 merged 1 commit into
gitx:masterfrom
goneng:fix-self-inflicted-index-refresh

Conversation

@goneng

@goneng goneng commented Sep 11, 2026 •

Copy link
Copy Markdown
Collaborator

Staging writes the index and reads it straight back, and a second later the repository watcher
reported that same write, so the whole index was read again for nothing.
The index now notes the stat fingerprint of the file a refresh is about to read, and
an index event is acted on only when the index on disk is no longer that one.

Impact of the change

External git commands:

action before after
opening a repository 9 3
staging a file 6 3
git add from a terminal 3 3
git reset <file> from a terminal 3 3
git commit from a terminal 3 3

(traced from a running GitX)

Only GitX's own writes are skipped.
Working directory events are left alone either way, since a file on disk carries
no fingerprint the view could have recorded.
The git reset row is the interesting one:
it writes the index and touches nothing else, and still refreshes.

Test plan

  • New PBGitCommitControllerRefreshTests: 4 tests on which events reach
    a refresh, of which testTheIndexThatWasJustReadIsNotReadAgain fails
    without the change
  • 3 more in PBGitIndexRefreshTests on the fingerprint bookkeeping,
    including an index that cannot be statted being reported as changed
  • make unit-test: 67 tests, 0 failures
  • Traced every external git command of a running GitX to produce the
    table above, staging from the UI and writing the index from a terminal

@goneng goneng changed the title Fix the index being read twice over for a write GitX made itself Fix the index being read twice over for a write GitX made itself (performance improvement) Sep 11, 2026
@goneng
goneng force-pushed the fix-self-inflicted-index-refresh branch 4 times, most recently from de82576 to c11db69 Compare September 13, 2026 04:33
@hannesa2 hannesa2 added the performance performance improvement label Sep 13, 2026
@hannesa2 hannesa2 changed the title Fix the index being read twice over for a write GitX made itself (performance improvement) Fix the index being read twice over for a write GitX made itself Sep 13, 2026
@goneng
goneng force-pushed the fix-self-inflicted-index-refresh branch from c11db69 to b8aea4b Compare September 13, 2026 06:34
Staging writes the index and reads it straight back, and a second later
the repository watcher reported that same write, so the whole index was
read again for nothing.

* Note which index a refresh is about to read, by the stat fingerprint
  the diff cache already relies on
* Act on an index event only when the index on disk is no longer the
  one that refresh read
* Leave working directory events alone, since a file on disk carries no
  fingerprint the view could have recorded

Opening a repository now runs one index refresh rather than three, and
staging a file one rather than two. An index written by anyone else
still reaches the view, tested with git add, git reset and git commit
run from a terminal.
@goneng
goneng force-pushed the fix-self-inflicted-index-refresh branch from b8aea4b to 3f7d41f Compare September 13, 2026 07:34
@goneng
goneng marked this pull request as ready for review September 13, 2026 07:51
@hannesa2
hannesa2 merged commit d73152e into gitx:master Sep 13, 2026
3 checks passed
@goneng
goneng deleted the fix-self-inflicted-index-refresh branch September 13, 2026 08:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance performance improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants