Skip to content

Commit

Permalink
TODO status: use sparse-index throughout
Browse files Browse the repository at this point in the history
By testing 'git -c core.fsmonitor= status -uno', we can check for the
simplest index operations that can be made sparse-aware. The necessary
implementation details are already integrated with sparse-checkout, so
modify command_requires_full_index to be zero for cmd_status().

By running the debugger for 'git status -uno' after that change, we find
two instances of ensure_full_index() that were added for extra safety,
but can be removed without issue.

In refresh_index(), we loop through the index entries. The
refresh_cache_ent() method copies the sparse directories into the
refreshed index without issue.

The loop within run_diff_files() skips things that are in stage 0 and
have skip-worktree enabled, so seems safe to disable ensure_full_index()
here.

TODO: performance numbers at this point are confusing:

Benchmark #1: full index (git -c core.fsmonitor= status -uno)
  Time (mean ± σ):      2.522 s ±  0.079 s    [User: 1.511 s, System: 0.833 s]
  Range (min … max):    2.454 s …  2.715 s    10 runs

Benchmark #2: sparse index, old (git -c core.fsmonitor= status -uno)
  Time (mean ± σ):      3.370 s ±  0.036 s    [User: 3.166 s, System: 0.294 s]
  Range (min … max):    3.318 s …  3.428 s    10 runs

Benchmark #3: sparse index (git -c core.fsmonitor= status -uno)
  Time (mean ± σ):      5.196 s ±  0.056 s    [User: 5.189 s, System: 0.185 s]
  Range (min … max):    5.138 s …  5.269 s    10 runs

This shows that the previous change (Benchmark #2) had some overhead with
ensure_full_index() compared to a full index (Benchmark #1) but the
current change got much slower for some reason! Note that
ensure_full_index() is not called anywhere in this process! What is
going on?

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
  • Loading branch information
derrickstolee committed Jan 25, 2021
1 parent 44418af commit 342025b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
3 changes: 3 additions & 0 deletions builtin/commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -1400,6 +1400,9 @@ int cmd_status(int argc, const char **argv, const char *prefix)
if (argc == 2 && !strcmp(argv[1], "-h"))
usage_with_options(builtin_status_usage, builtin_status_options);

prepare_repo_settings(the_repository);
the_repository->settings.command_requires_full_index = 0;

status_init_config(&s, git_status_config);
argc = parse_options(argc, argv, prefix,
builtin_status_options,
Expand Down
2 changes: 0 additions & 2 deletions diff-lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
uint64_t start = getnanotime();
struct index_state *istate = revs->diffopt.repo->index;

ensure_full_index(istate);

diff_set_mnemonic_prefix(&revs->diffopt, "i/", "w/");

refresh_fsmonitor(istate);
Expand Down
1 change: 0 additions & 1 deletion read-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -1561,7 +1561,6 @@ int refresh_index(struct index_state *istate, unsigned int flags,
*/
preload_index(istate, pathspec, 0);

ensure_full_index(istate);
for (i = 0; i < istate->cache_nr; i++) {
struct cache_entry *ce, *new_entry;
int cache_errno = 0;
Expand Down
10 changes: 7 additions & 3 deletions t/t1092-sparse-checkout-compatibility.sh
Original file line number Diff line number Diff line change
Expand Up @@ -382,12 +382,16 @@ test_expect_success 'sparse-index is expanded and converted back' '
GIT_TRACE2_EVENT="$(pwd)/trace2.txt" GIT_TRACE2_EVENT_NESTING=10 \
git -C sparse-index -c core.fsmonitor="" reset --hard &&
test_region index convert_to_sparse trace2.txt &&
test_region index ensure_full_index trace2.txt &&
test_region index ensure_full_index trace2.txt
'

rm trace2.txt &&
test_expect_success 'sparse-index is not expanded' '
init_repos &&
rm -f trace2.txt &&
GIT_TRACE2_EVENT="$(pwd)/trace2.txt" GIT_TRACE2_EVENT_NESTING=10 \
git -C sparse-index -c core.fsmonitor="" status -uno &&
test_region index ensure_full_index trace2.txt
test_region ! index ensure_full_index trace2.txt
'

test_done

0 comments on commit 342025b

Please sign in to comment.