Re:Re: [PATCH] read-cache: hash the shared index even with index.skipHash
- From
- Xing Xin <bupt_xingxin@163.com>
- Date
- Nov 27, 2026, 12:59 UTC
- Message-ID
- <5dfa732c.94b8.1a21d16a974.Coremail.bupt_xingxin@163.com>
- In-Reply-To
- <xmqqld6fjt55.fsf@gitster.g>
At 2026-11-27 03:21:26, "Junio C Hamano" <gitster@pobox.com> wrote:
Show 8 quoted lines
> It is correct to point out that the two "features", skipHash and > splitIndex, are incompatible. With skipHash, splitIndex will not > correctly work. We can say skipHash breaks splitIndex. > > But does this change to _force_ the base index files to be hashed, > against the user's wish expressed by skipHash, take us in a better > direction, I have to wonder? With this change, skipHash's promise to > improve performance is not kept. We can say splitIndex breaks skipHash.
You are right, and the log message overstates the case when it says that this "keeps most of the benefit". As the numbers below show, the split index file is small enough that skipping its hash saves next to nothing, so with this patch index.skipHash has little effect once a split index is in use.
That said, I do not think both can be kept without changing the index format. Readers die() unless the "link" extension names the trailing hash of the shared index, and a trailer that is neither null nor the real hash makes "git fsck" fail. So a shared index written without its hash can only be called sharedindex.<null OID>, which is exactly what goes wrong today. One of the two has to give.
Show 9 quoted lines
> Stepping back a bit, isn't the expectation of splitIndex that these > incremental modifications held in non-base index files are relatively > small, thanks to the bulk of data that the base index file holds > covering almost everything in the repository? In other words, isn't the > use of splitIndex a strong sign that the base index file would benefit > the most from skipHash? And this patch is breaking the skipHash feature > for the use case that would benefit the most. And not hashing the index > files that are not bases would not save as much, since they are expected > to be much smaller.
Per write, yes. But what skipHash saves is the hashing done on each write, and the shared index is only written when it is rewritten, which the split index is designed to make rare. The frequent writes are of the small split index, where, as you say, there is little to save.
Show 5 quoted lines
> I wonder if going in the other direction, i.e., when both are enabled, > disabling splitIndex and working only on the base hash, would be an > alternative that is equally viable as this change? Both will *break* > the promise of one feature so that the result can live with the other > feature. What are the pros and cons between them?
I see three ways to resolve it when both are set:
1. disable the split index and keep skipHash (your suggestion),
2. keep the split index and ignore index.skipHash while it is in
use,
3. keep both, but always hash the shared index (this patch).To compare them, I measured a repository with 100k files in 1,000 directories, index v4 (7.0MB) with the untracked cache enabled, so that the split index carries the cache-tree and untracked cache extensions as it would in practice. Each round changes K files and runs "git add -u", "git commit", "git status" (after touching the files), and "git checkout HEAD~1" and back. 1 and 2 are emulated by turning the other setting off. The times are the index write and read regions from trace2, median of 7 runs, averaged over add, commit and status (Apple M4 Pro, SHA1DC):
index write (ms) index .git/index
K=1 K=100 K=10000 read K=1 / K=10000
neither 18.3 15.2 15.5 3 ms 7.0 / 7.0 MB
1: skipHash only 6.1 6.0 6.1 3 ms 7.0 / 7.0 MB
2: splitIndex only 0.4 0.4 1.9 3 ms 0.07 / 0.75 MB
3: both, this patch 0.3 0.3 0.9 3 ms 0.07 / 0.75 MBRewriting the whole index takes 15-20ms with neither feature and 6ms with skipHash; rewriting the shared index takes 15-22ms with 2 or 3, as both hash it. The checkout round trip, which writes the index twice, shows the same pattern.
- The write time hardly depends on K: without a split index every write covers all entries, and with one the split index stays small (0.75MB at K=10000). No K up to 10000 (10% of the entries) made 2 or 3 rewrite the shared index; that takes new or re-created entries beyond splitIndex.maxPercentChange (20% by default), e.g. when checking out a distant branch.
- 1 cuts each write from ~15-18ms to ~6ms. 2 cuts it to under 2ms, but pays ~10-15ms more than 1 whenever it rewrites the shared index, so it comes out ahead unless about one write in three does so.
- 3 differs from 2 only in hashing .git/index, which costs ~0.1ms for 0.07MB and ~1ms for 0.75MB here. That is all index.skipHash can still save with a split index.
- The index read time is the same ~3ms in all four.
- At this size, all of this is small next to the run times of the commands (110ms to 3.8s), which are dominated by the work on the files themselves, and the differences there are mostly within the noise.
Performance aside, the two settings do not come from symmetric places, which matters for 1:
- index.skipHash is only ever a configuration variable: it is either implied by feature.manyFiles, or set as index.skipHash, by the user or by Scalar, which writes index.skipHash=true into the repository configuration and resets it on "scalar reconfigure".
- The split index is enabled by core.splitIndex, which neither a feature.* setting nor Scalar sets, or by "git update-index --split-index", which stays in effect while core.splitIndex is unset.
When both are set in the configuration, there is no telling which one the user cares about more. But 1 would let a default implied by feature.manyFiles override an explicit core.splitIndex, although feature.* is documented to only change defaults. For "git update-index --split-index", 1 would either have to let a configuration variable override a command line option, whereas today the option still takes effect, with a warning, when core.splitIndex is false, or honor the option for that write, which needs the change in this patch anyway. And in a Scalar enlistment, core.splitIndex would only work after setting index.skipHash=false, and would stop working again at the next "scalar reconfigure". There is also precedent for the split index taking priority: the sparse index is not written while a split index is in use (see is_sparse_index_allowed()).
Between 2 and 3 the performance is practically the same, so it comes down to principle. 3 deviates from the configuration only where the index format forces it to. 2 is simpler to explain ("index.skipHash has no effect with a split index") and keeps the checksum of .git/index, at the cost of ignoring a setting it does not strictly need to ignore. I lean towards 3, but would be happy to switch to 2 if you prefer the simpler rule; the difference is a single condition.
Once we settle on the direction, I will send a v2 with the log message and documentation updated accordingly.
Thanks.