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

[PATCH v1] add: speed up cmd_add() by utilizing read_cache_preload()

From
Ben Peart <peartben@gmail.com>
Date
Nov 2, 2018, 13:30 UTC
Message-ID
<20181102133050.10756-1-peartben@gmail.com>
From: Ben Peart <benpeart@microsoft.com>

During an "add", a call is made to run_diff_files() which calls check_remove() for each index-entry. The preload_index() code distributes some of the costs across multiple threads.

Because the files checked are restricted to pathspec, adding individual files makes no measurable impact but on a Windows repo with ~200K files, 'git add .' drops from 6.3 seconds to 3.3 seconds for a 47% savings.

Signed-off-by: Ben Peart <benpeart@microsoft.com>
---
Notes:
    Base Ref: master
    Web-Diff: https://github.com/benpeart/git/commit/fc4830b545
    Checkout: git fetch https://github.com/benpeart/git add-preload-index-v1 && git checkout fc4830b545
 builtin/add.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/builtin/add.c b/builtin/add.c
index ad49806ebf..f65c172299 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -445,11 +445,6 @@ int cmd_add(int argc, const char **argv, const char *prefix)
 		return 0;
 	}
 
-	if (read_cache() < 0)
-		die(_("index file corrupt"));
-
-	die_in_unpopulated_submodule(&the_index, prefix);
-
 	/*
 	 * Check the "pathspec '%s' did not match any files" block
 	 * below before enabling new magic.
@@ -459,6 +454,10 @@ int cmd_add(int argc, const char **argv, const char *prefix)
 		       PATHSPEC_SYMLINK_LEADING_PATH,
 		       prefix, argv);
 
+	if (read_cache_preload(&pathspec) < 0)
+		die(_("index file corrupt"));
+
+	die_in_unpopulated_submodule(&the_index, prefix);
 	die_path_inside_submodule(&the_index, &pathspec);
 
 	if (add_new_files) {

base-commit: 4ede3d42dfb57f9a41ac96a1f216c62eb7566cc2
-- 
2.18.0.windows.1
Next: Junio C Hamano
Message 1 of 6 in “add: speed up cmd_add() by utilizing read_cache_preload()”
  1. add: speed up cmd_add() by utilizing read_cache_preload()Ben Peart, Nov 2, 2018
  2. Junio C HamanoNov 2, 2018
  3. Ben PeartNov 2, 2018
  4. Duy NguyenNov 2, 2018
  5. Junio C HamanoNov 3, 2018
  6. Duy NguyenNov 3, 2018

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.