git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: git-diff in a worktree is an order of magnitude slower?

From
Jeff King <peff@peff.net>
Date
Jun 28, 2026, 08:36 UTC
Message-ID
<20260628083628.GB3594700@coredump.intra.peff.net>
In-Reply-To
<xmqqik7a4vhp.fsf@gitster.g>
On Mon, Jun 22, 2026 at 05:20:34AM -0700, Junio C Hamano wrote:
Show 23 quoted lines
> Jeff King <peff@peff.net> writes:
> 
> > Yes, though that implies comparing the index and file mtimes with
> > nanosecond precision.  We have that precision stored (at least
> > when the system supports it) but I'm not sure if that comparison would
> > run afoul of the reasons USE_NSEC was not the default in the first
> > place.
> >
> > I guess not? The problem there is that the nanosecond portion would
> > sometimes get wiped if the entry was dropped from the kernel's in-memory
> > cache. And then stat-matching would not work. But if we are talking
> > about strictly asking "is this mtime later than that mtime", then I
> > think the worst case is that we fall back to the current behavior.
> 
> Right, and you are right to point out that for the purpose of
> comparing mtimes of files' and the index file, this would make it
> unworkable.  I can imagine that a file and the index may have been
> written within the same millisecond but we can tell that the former
> slightly earlier than the latter (or the other way around) with
> nanoseconds resolution, then only one of the two lose the sub millisecond
> resolution but not the other due to its in-core inode evicted out of
> the cache.  Depending on which one survives (and keeps a non-zero
> sub millisecond part), they can compare differently.

Hmm, yeah. I was thinking there might be some mitigating factor because we're comparing stat information that is stored in the index, and not against a fresh stat() call. But that's not true.

We are using stat() information stored in the index from a file that was written in the same second as that index (otherwise we do not care about nanoseconds at all). But the index does not store its own mtime. At the time of reading, we will fstat() it fresh, so we may see the truncated mtime value.

In that case we'd always see the index as older than it really is. Which I think does fail in the favorable direction for us (we assume the too-new file is possibly racy and err on the side of caution).

But I don't think it rules out seeing the truncation in the other direction. The original index write would have to be done in the same second that the tracked file is written (because we only care about nanoseconds when that is true). So it implies that the tracked file was written, had its inode evicted, and then was re-read from disk all in the same second that the index is being written, and the index inode itself is never evicted. That seems unlikely but not impossible.

Anyway, it's all sufficiently scary that I think it should stay conditional on USE_NSEC. I do suspect that USE_NSEC is safe at least on Linux these days (see my response to Patrick elsewhere).

-Peff
Previous: Junio C HamanoNext: Junio C Hamano
Message 16 of 19 in “git-diff in a worktree is an order of magnitude slower?”
  1. D. Ben KnobleJun 8, 2026
  2. Jeff KingJun 9, 2026
  3. D. Ben KnobleJun 9, 2026
  4. Jeff KingJun 11, 2026
  5. Junio C HamanoJun 11, 2026
  6. brian m. carlsonJun 11, 2026
  7. D. Ben KnobleJun 20, 2026
  8. Junio C HamanoJun 21, 2026
  9. Junio C HamanoJun 21, 2026
  10. Jeff KingJun 21, 2026
  11. Jeff KingJun 21, 2026
  12. Junio C HamanoJun 21, 2026
  13. Jeff KingJun 21, 2026
  14. Junio C HamanoJun 21, 2026
  15. Junio C HamanoJun 22, 2026
  16. Jeff KingJun 28, 2026
  17. Junio C HamanoJun 21, 2026
  18. Jeff KingJun 21, 2026
  19. D. Ben KnobleJul 3, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.