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

[PATCH 1/2] sha1_file: freshen pack objects before loose

From
Jeff King <peff@peff.net>
Date
Apr 20, 2015, 19:54 UTC
Message-ID
<20150420195403.GA15760@peff.net>
In-Reply-To
<20150420195337.GA15447@peff.net>

When writing out an object file, we first check whether it already exists and if so optimize out the write. Prior to 33d4221, we did this by calling has_sha1_file(), which will check for packed objects followed by loose. Since that commit, we check loose objects first.

For the common case of a repository whose objects are mostly packed, this means we will make a lot of extra access() system calls checking for loose objects. We should follow the same packed-then-loose order that all of our other lookups use.

Reported-by: Stefan Saasen <ssaasen@atlassian.com>
Signed-off-by: Jeff King <peff@peff.net>
---
 sha1_file.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/sha1_file.c b/sha1_file.c
index 88f06ba..822aaef 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -3014,7 +3014,7 @@ int write_sha1_file(const void *buf, unsigned long len, const char *type, unsign
 	write_sha1_file_prepare(buf, len, type, sha1, hdr, &hdrlen);
 	if (returnsha1)
 		hashcpy(returnsha1, sha1);
-	if (freshen_loose_object(sha1) || freshen_packed_object(sha1))
+	if (freshen_packed_object(sha1) || freshen_loose_object(sha1))
 		return 0;
 	return write_loose_object(sha1, hdr, hdrlen, buf, len, 0);
 }
-- 
2.4.0.rc2.384.g7297a4a
Previous: Jeff KingNext: Stefan Saasen
Message 6 of 19 in “[BUG] Performance regression due to #33d4221: write_sha1_file: freshen existing objects”
  1. Stefan SaasenApr 17, 2015
  2. Jeff KingApr 17, 2015
  3. Junio C HamanoApr 17, 2015
  4. Stefan SaasenApr 18, 2015
  5. Jeff KingApr 20, 2015
  6. 1/2 sha1_file: freshen pack objects before looseJeff King, Apr 20, 2015
  7. Stefan SaasenApr 21, 2015
  8. 2/2 sha1_file: only freshen packs once per runJeff King, Apr 20, 2015
  9. Stefan SaasenApr 21, 2015
  10. Junio C HamanoApr 20, 2015
  11. Jeff KingApr 20, 2015
  12. Junio C HamanoApr 20, 2015
  13. Jeff KingApr 20, 2015
  14. Stefan SaasenApr 21, 2015
  15. Junio C HamanoApr 21, 2015
  16. Junio C HamanoApr 21, 2015
  17. Stefan SaasenApr 22, 2015
  18. Junio C HamanoApr 22, 2015
  19. Stefan SaasenApr 22, 2015

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.