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

Re: [PATCH v4] read-cache: do not trust a size change when conversion is active

From
Torsten Bögershausen <tboegi@web.de>
Date
Oct 13, 2026, 18:01 UTC
Message-ID
<20261013180116.GA26647@tb-raspi4>
In-Reply-To
<20261013065915.879-1-curtis.allen.smith@gmail.com>
On Tue, Oct 13, 2026 at 12:58:28AM -0600, Curtis Allen Smith wrote:

Thanks for the fast and good answers everybody. As a comment: no, I didn't intend to tak over the series - just want to move things forward. And the Helped-By is of course ok.

I don't know if we need more explanations why this change is needed (after so long time), but here is my undestanding:

When we run

git init t && cd t printf 'one\ntwo\nthree\n' >file.txt git add . && git commit -m init

followed by
printf 'two\ntwo\nthree\n' >file.txt

then Git will notice that the actual mtime as a result of lstat() is different from what is recorded in the index. As a result, git needs to re-hash the content to conclude if the content has changed. However, in order to avoid the expensive hashing, Git concludes that when the size of a file has changed then the content -must- be different - files having a different size are never identical. This did work well until the .gitattributes feature was introduced. Now, in the example below, a file having a different size -can- result in the same blob once it is commited. Therefore this patch does need to check if attributes (for input conversions) are defined. If not, take the shortcut and conclude that the file is modified. But if, take the long way, which is what happens when only mtime (and possibly other elements from struct st are changed.

And now the new size, mtime (and the rest) will be recorded in the index. So it is a one-time cost.

Does this make sense ?
Show 64 quoted lines
> "git status" can report a file as modified while "git diff" and
> "git add" agree that its contents are unchanged:
> 
> 	git init t && cd t
> 	printf '* text eol=lf\n' >.gitattributes
> 	printf 'one\ntwo\nthree\n' >file.txt
> 	git add . && git commit -m init
> 
> 	printf 'one\r\ntwo\r\nthree\r\n' >file.txt
> 
> 	git status --short      # ->  M file.txt
> 	git diff                # -> empty
> 	git add file.txt        # -> nothing to commit
> 
> ie_modified() takes a change in the file's size since the index
> entry was last refreshed as proof that the file is modified, without
> looking at the contents.  A size change proves only that the bytes in
> the working tree changed.  When the path is subject to conversion
> (the "text" and "eol" attributes, core.autocrlf, a clean filter),
> different bytes can convert to the same blob, as the CRLF rewrite
> above does.
> 
> For such a path, fall through to ce_modified_check_fs(), as is
> already done when only the mtime changed.  Paths without conversion
> return early as before.
> 
> Helped-by: Torsten Bögershausen <tboegi@web.de>
> Signed-off-by: Curtis Allen Smith <curtis.allen.smith@gmail.com>
> ---
> Changes since v3:
>  - The fix is inlined into the condition in ie_modified(), with no
>    helper function.
>  - Shorter log message, using Junio's wording; the "real life"
>    examples are gone.
> 
> Cost, i9-14900K under WSL2, warm cache, fastest of 5 runs of
> "git status -uno", stock 6de20f6 against this patch:
> 
> 	10000 files x 2.6 KB, no conversion       stock      v4
> 	  clean tree                               5 ms     5 ms
> 	  10000 files with a size change          26 ms    24 ms
> 
> 	10000 files x 2.6 KB, "* text=auto eol=lf"
> 	  clean tree                               5 ms     5 ms
> 	  10000 genuinely modified                25 ms   137 ms
> 	  10000 CRLF-rewritten, 1st run           21 ms   143 ms
> 	  the same, every run after               21 ms     5 ms
> 
> 	200 files x 1 MB, "* text=auto eol=lf"
> 	  clean tree                               3 ms     3 ms
> 	  200 genuinely modified                   3 ms   498 ms
> 	  200 CRLF-rewritten, 1st run              3 ms   584 ms
> 	  the same, every run after                3 ms     3 ms
> 
> The attribute lookup happens only for a path whose size changed, so a
> clean tree pays nothing, and a tree without conversion pays one
> lookup per size-changed path (the first block).  A converted path
> whose size changed is now read, converted and hashed, which is what
> already happens when only its mtime changes.  Stock git keeps
> reporting the CRLF-rewritten files as modified on every run.
> 
> A follow-up that skips the conversion and the hash when the length
> already rules out a match is ready if wanted.  It takes the
> "genuinely modified" rows to 57 ms and 25 ms.
[snip]
Previous: Curtis SmithNext: Curtis Allen Smith
Message 16 of 37 in “utf8.c: Prepare workaround for iconv under macOS 14/15”
  1. 1/2 utf8.c: Prepare workaround for iconv under macOS 14/15tboegi@web.de, Jan 11, 2026
  2. Junio C HamanoJan 12, 2026
  3. 1/2 utf8.c: Prepare workaround for iconv under macOS 14/15tboegi@web.de, Jan 12, 2026
  4. 0/2 Workaround for iconv under macOS 14/15tboegi@web.de, Jan 12, 2026
  5. 2/2 utf8.c: Enable workaround for iconv under macOS 14/15tboegi@web.de, Jan 12, 2026
  6. 0/1 read-cache: do not trust a size change when conversiontboegi@web.de, Oct 12, 2026
  7. 1/1 read-cache: do not trust a size change when conversion is activetboegi@web.de, Oct 12, 2026
  8. Junio C HamanoOct 12, 2026
  9. Junio C HamanoOct 13, 2026
  10. Curtis SmithOct 13, 2026
  11. Johannes SixtOct 13, 2026
  12. Curtis SmithOct 13, 2026
  13. read-cache: do not trust a size change when conversion is activeCurtis Allen Smith, Oct 13, 2026
  14. Phillip WoodOct 13, 2026
  15. Curtis SmithOct 13, 2026
  16. Torsten BögershausenOct 13, 2026
  17. read-cache: do not trust a size change when conversion is activeCurtis Allen Smith, Oct 13, 2026
  18. Junio C HamanoOct 13, 2026
  19. Torsten BögershausenOct 18, 2026
  20. Junio C HamanoOct 19, 2026
  21. Torsten BögershausenOct 20, 2026
  22. 0/1 More cs/read-cache-conversion-sizetboegi@web.de, Oct 26, 2026
  23. 1/1 read-cache: optimize file size change when conversion is activetboegi@web.de, Oct 26, 2026
  24. 0/2 read-cache: do not trust a size change when conversion is activetboegi@web.de, Nov 27, 2026
  25. Junio C HamanoNov 28, 2026
  26. 1/2 read-cache: do not trust a size change when conversion is activetboegi@web.de, Nov 27, 2026
  27. Junio C HamanoNov 28, 2026
  28. Torsten BögershausenNov 28, 2026
  29. Junio C HamanoNov 29, 2026
  30. 2/2 read-cache: optimize file size change when conversion is activetboegi@web.de, Nov 27, 2026
  31. Junio C HamanoNov 28, 2026
  32. 1/1 read-cache: do not trust a size change when conversion is activetboegi@web.de, Nov 29, 2026
  33. Junio C HamanoNov 29, 2026
  34. Junio C HamanoNov 29, 2026
  35. Junio C HamanoNov 29, 2026
  36. Torsten BögershausenNov 29, 2026
  37. Junio C HamanoNov 29, 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.