I am currently on Mac.
In Git 2.35.1, when I cloned my repository, it took 7 seconds to enumerate the untracked files and when I did time git status
, it took approximately 2 seconds.
And, when I checkout to other branch it took approximately 15 seconds and when I checkout back to my main repo git status
took 15 seconds (which should not take this much time).
Work-around for this in (2.35.1) was:
I set core.untrackedCache=true
and GIT_FORCE_UNTRACKED_CACHE=1
which helped to update the untracked cache and improve the performance of git status
of (approximately 4 seconds) which are mentioned in most of Stack Overflow answers.
stack-overflow question
But now in Git 2.36.1, this work-around doesn't seem to work. It takes approximately 20 seconds on all branches.
Possible changes in the code:
In Git 2.35.1, code in dir.c
:
if (dir->untracked) {
static int force_untracked_cache = -1;
if (force_untracked_cache < 0)
force_untracked_cache =
git_env_bool("GIT_FORCE_UNTRACKED_CACHE", 0);
if (force_untracked_cache &&
dir->untracked == istate->untracked &&
(dir->untracked->dir_opened ||
dir->untracked->gitignore_invalidated ||
dir->untracked->dir_invalidated))
istate->cache_changed |= UNTRACKED_CHANGED;
if (dir->untracked != istate->untracked) {
FREE_AND_NULL(dir->untracked);
}
}
and the same in Git 2.36.1, code in dir.c
:
if (dir->untracked) {
static int force_untracked_cache = -1;
if (force_untracked_cache < 0)
force_untracked_cache =
git_env_bool("GIT_FORCE_UNTRACKED_CACHE", -1);
if (force_untracked_cache < 0)
force_untracked_cache = (istate->repo->settings.core_untracked_cache == UNTRACKED_CACHE_WRITE);
if (force_untracked_cache &&
dir->untracked == istate->untracked &&
(dir->untracked->dir_opened ||
dir->untracked->gitignore_invalidated ||
dir->untracked->dir_invalidated))
istate->cache_changed |= UNTRACKED_CHANGED;
if (dir->untracked != istate->untracked) {
FREE_AND_NULL(dir->untracked);
}
}
Edit 1 :
GIT_TRACE_PERFORMANCE=1 git status
12:44:54.433726 read-cache.c:2437 performance: 0.092473000 s: read cache .git/index
12:44:54.915510 read-cache.c:2480 performance: 0.481510000 s: read cache .git/sharedindex.f6119c27ffbee28b22e1baa47e66f355491292e
12:45:05.369546 preload-index.c:154 performance: 10.374954000 s: preload index
Refresh index: 100% (1164397/1164397), done.
12:45:05.421952 read-cache.c:1721 performance: 10.427363000 s: refresh index
12:45:05.464869 diff-lib.c:266 performance: 0.040042000 s: diff-files
12:45:05.478549 unpack-trees.c:1884 performance: 0.000028000 s: traverse_trees
12:45:05.493406 unpack-trees.c:424 performance: 0.000008000 s:check_updates
12:45:05.493444 unpack-trees.c:1974 performance: 0.028052000 s: unpack_trees
12:45:05.493454 diff-lib.c:629 performance: 0.028099000 s: diff-index
On branch default
Your branch is up to date with 'origin/default'.
and when I switch the branch and come back to default branch below is the performance. I am not sure why the read-cache.c below is taking this much time!
GIT_TRACE_PERFORMANCE=1 git status
12:22:24.343325 read-cache.c:2437 performance: 0.112630000 s: read cache .git/index
12:22:42.618493 read-cache.c:2480 performance: 18.274836000 s:read cache .git/sharedindex.5ad8766e997830f32884b42ca5b17c2be6a19f1
12:22:53.559907 preload-index.c:154 performance: 10.840555000 s: preload index
Refresh index: 100% (1164397/1164397), done.
12:22:53.646110 read-cache.c:1721 performance: 10.926760000 s: refresh index
12:22:53.685650 diff-lib.c:266 performance: 0.038002000 s: diff-files
12:22:53.713422 unpack-trees.c:1884 performance: 0.000042000 s: traverse_trees
12:22:53.726052 unpack-trees.c:424 performance: 0.000008000 s: check_updates
12:22:53.726085 unpack-trees.c:1974 performance: 0.028672000 s:unpack_trees
12:22:53.726094 diff-lib.c:629 performance: 0.039895000 s: diff-index
12:23:03.568051 read-cache.c:3121 performance: 0.161937000 s: write index, changed mask = c
On branch default
Your branch is up to date with 'origin/default'.
You are in a sparse checkout with tracked files present.
Changes not staged for commit:
Modified:
Modified:
….
Edit 2:
I did some research and found that .git/sharedindex. is created when I set core.splitindex =true and sharedindex is taking time. so does it has to do anything with performance?
How can I solve this untracked files cache performance issue? Is there any workaround?