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

Re: [PATCH/RFC v3 7/9] write_entry(): use fstat() instead of lstat() when file is open

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 4, 2009, 18:41 UTC
Message-ID
<7vfxiut57t.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<49899FA4.2020003@viscovery.net>
Johannes Sixt <j.sixt@viscovery.net> writes:
Show 33 quoted lines
> Kjetil Barvik schrieb:
>> Currently inside write_entry() we do an lstat(path, &st) call on a
>> file which have just been opened inside the exact same function.  It
>> should be better to call fstat(fd, &st) on the file while it is open,
>> and it should be at least as fast as the lstat() method.
> ...
>> @@ -145,6 +146,11 @@ static int write_entry(struct cache_entry *ce, char *path, const struct checkout
>>  		}
>>  
>>  		wrote = write_in_full(fd, new, size);
>> +		/* use fstat() only when path == ce->name */
>> +		if (state->refresh_cache && !to_tempfile && !state->base_dir_len) {
>> +			fstat(fd, &st);
>> +			fstat_done = 1;
>> +		}
>>  		close(fd);
>
> I've a bad gut feeling about this: It may not work as expected on Windows
> because there is this statement in the documentation:
>
>   "The only guarantee about a file timestamp is that the file time is
>    correctly reflected when the handle that makes the change is closed."
>
> (http://msdn.microsoft.com/en-us/library/ms724290(VS.85).aspx)
>
> We are operating on a temporary file. It could happen that the fstat()
> returns the time when the file was created, as opposed to when the
> write_in_full() was completed successfully. The fstat()ed time ends up in
> the index, but it can be different from what later lstat() calls report
> (and the file would be regarded as modified).
>
> I have the suspicion that the gain from this patch is minimal. Would you
> mind playing it safe and drop this patch?

Hmm, write_entry() is actually called once per one path we write out, and the fstat() is added to the common case (no --tempfile, no --prefix=<dir> checkout), which would mean that if there were any performance gain from this change, it was obtained by trading correctness away. Sad.

Previous: Johannes SixtNext: Kjetil Barvik
Message 13 of 23 in “git checkout: more cleanups, optimisation, less lstat() calls”
  1. 0/9 git checkout: more cleanups, optimisation, less lstat() callsKjetil Barvik, Feb 4, 2009
  2. 1/9 lstat_cache(): small cleanup and optimisationKjetil Barvik, Feb 4, 2009
  3. 2/9 lstat_cache(): generalise longest_match_lstat_cache()Kjetil Barvik, Feb 4, 2009
  4. 3/9 lstat_cache(): swap func(length, string) into func(string, length)Kjetil Barvik, Feb 4, 2009
  5. 4/9 unlink_entry(): introduce schedule_dir_for_removal()Kjetil Barvik, Feb 4, 2009
  6. Junio C HamanoFeb 4, 2009
  7. Junio C HamanoFeb 4, 2009
  8. Kjetil BarvikFeb 4, 2009
  9. 5/9 create_directories(): remove some memcpy() and strchr() callsKjetil Barvik, Feb 4, 2009
  10. 6/9 write_entry(): cleanup of some duplicated codeKjetil Barvik, Feb 4, 2009
  11. 7/9 write_entry(): use fstat() instead of lstat() when file is openKjetil Barvik, Feb 4, 2009
  12. Johannes SixtFeb 4, 2009
  13. Junio C HamanoFeb 4, 2009
  14. Kjetil BarvikFeb 4, 2009
  15. Junio C HamanoFeb 4, 2009
  16. Johannes SixtFeb 5, 2009
  17. Johannes SchindelinFeb 5, 2009
  18. Junio C HamanoFeb 5, 2009
  19. Kjetil BarvikFeb 6, 2009
  20. Johannes SchindelinFeb 6, 2009
  21. Kjetil BarvikFeb 14, 2009
  22. 8/9 show_patch_diff(): remove a call to fstat()Kjetil Barvik, Feb 4, 2009
  23. 9/9 lstat_cache(): print a warning if doing ping-pong between cache typesKjetil Barvik, Feb 4, 2009

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.