Skip to content

Commit

Permalink
features: feature.manyFiles implies fast index writes
Browse files Browse the repository at this point in the history
The recent addition of the index.skipHash config option allows index
writes to speed up by skipping the hash computation for the trailing
checksum. This is particularly critical for repositories with many files
at HEAD, so add this config option to two cases where users in that
scenario may opt-in to such behavior:

 1. The feature.manyFiles config option enables some options that are
    helpful for repositories with many files at HEAD.

 2. 'scalar register' and 'scalar reconfigure' set config options that
    optimize for large repositories.

In both of these cases, set index.skipHash=true to gain this
speedup. Add tests that demonstrate the proper way that
index.skipHash=true can override feature.manyFiles=true.

Signed-off-by: Derrick Stolee <derrickstolee@github.com>
  • Loading branch information
derrickstolee committed Dec 7, 2022
1 parent a20bf8d commit 77bf5d5
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 4 deletions.
3 changes: 3 additions & 0 deletions Documentation/config/feature.txt
Expand Up @@ -23,6 +23,9 @@ feature.manyFiles::
working directory. With many files, commands such as `git status` and
`git checkout` may be slow and these new defaults improve performance:
+
* `index.skipHash=true` speeds up index writes by not computing a trailing
checksum.
+
* `index.version=4` enables path-prefix compression in the index.
+
* `core.untrackedCache=true` enables the untracked cache. This setting assumes
Expand Down
7 changes: 4 additions & 3 deletions read-cache.c
Expand Up @@ -2923,12 +2923,13 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
int ieot_entries = 1;
struct index_entry_offset_table *ieot = NULL;
int nr, nr_threads;
int skip_hash;

f = hashfd(tempfile->fd, tempfile->filename.buf);

if (!git_config_get_maybe_bool("index.skiphash", &skip_hash))
f->skip_hash = skip_hash;
if (istate->repo) {
prepare_repo_settings(istate->repo);
f->skip_hash = istate->repo->settings.index_skip_hash;
}

for (i = removed = extended = 0; i < entries; i++) {
if (cache[i]->ce_flags & CE_REMOVE)
Expand Down
2 changes: 2 additions & 0 deletions repo-settings.c
Expand Up @@ -47,6 +47,7 @@ void prepare_repo_settings(struct repository *r)
}
if (manyfiles) {
r->settings.index_version = 4;
r->settings.index_skip_hash = 1;
r->settings.core_untracked_cache = UNTRACKED_CACHE_WRITE;
}

Expand All @@ -61,6 +62,7 @@ void prepare_repo_settings(struct repository *r)
repo_cfg_bool(r, "pack.usesparse", &r->settings.pack_use_sparse, 1);
repo_cfg_bool(r, "core.multipackindex", &r->settings.core_multi_pack_index, 1);
repo_cfg_bool(r, "index.sparse", &r->settings.sparse_index, 0);
repo_cfg_bool(r, "index.skiphash", &r->settings.index_skip_hash, r->settings.index_skip_hash);

/*
* The GIT_TEST_MULTI_PACK_INDEX variable is special in that
Expand Down
1 change: 1 addition & 0 deletions repository.h
Expand Up @@ -42,6 +42,7 @@ struct repo_settings {
struct fsmonitor_settings *fsmonitor; /* lazily loaded */

int index_version;
int index_skip_hash;
enum untracked_cache_setting core_untracked_cache;

int pack_use_sparse;
Expand Down
1 change: 1 addition & 0 deletions scalar.c
Expand Up @@ -143,6 +143,7 @@ static int set_recommended_config(int reconfigure)
{ "credential.validate", "false", 1 }, /* GCM4W-only */
{ "gc.auto", "0", 1 },
{ "gui.GCWarning", "false", 1 },
{ "index.skipHash", "false", 1 },
{ "index.threads", "true", 1 },
{ "index.version", "4", 1 },
{ "merge.stat", "false", 1 },
Expand Down
13 changes: 12 additions & 1 deletion t/t1600-index.sh
Expand Up @@ -72,7 +72,18 @@ test_expect_success 'index.skipHash config option' '
test_trailing_hash .git/index >hash &&
echo $(test_oid zero) >expect &&
test_cmp expect hash &&
git fsck
git fsck &&
rm -f .git/index &&
git -c feature.manyFiles=true add a &&
test_trailing_hash .git/index >hash &&
test_cmp expect hash &&
rm -f .git/index &&
git -c feature.manyFiles=true \
-c index.skipHash=false add a &&
test_trailing_hash .git/index >hash &&
! test_cmp expect hash
)
'

Expand Down

0 comments on commit 77bf5d5

Please sign in to comment.