add: speed up cmd_add() by utilizing read_cache_preload()

During an "add", a call is made to run_diff_files() which calls check_removed() 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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ben Peart committed Nov 2, 2018 at 09:30 UTC d1664e73ad96aa08735bf81d48ec0fb6d196cc3e
1 file changed +4 -5
builtin/add.c
+4 -5
@@ -445,11 +445,6 @@ int cmd_add(int argc, const char **argv, const char *prefix)
445 return 0;
446 }
447
448 - if (read_cache() < 0)
449 - die(_("index file corrupt"));
450 -
451 - die_in_unpopulated_submodule(&the_index, prefix);
452 -
448 /*
449 * Check the "pathspec '%s' did not match any files" block
450 * below before enabling new magic.
@@ -459,6 +454,10 @@ int cmd_add(int argc, const char **argv, const char *prefix)
454 PATHSPEC_SYMLINK_LEADING_PATH,
455 prefix, argv);
456
457 + if (read_cache_preload(&pathspec) < 0)
458 + die(_("index file corrupt"));
459 +
460 + die_in_unpopulated_submodule(&the_index, prefix);
461 die_path_inside_submodule(&the_index, &pathspec);
462
463 if (add_new_files) {