我目前使用的是Mac电脑。
在Git 2.35.1版本中,当我克隆我的代码库时,需要7秒钟来枚举未跟踪的文件。当我执行time git status
命令时,大约需要2秒钟。
而当我切换到其他分支时,需要大约15秒钟,当我切换回我的主代码库时,git status
需要15秒钟(这不应该花费这么长时间)。
在(2.35.1)中的解决方法是:
我设置了core.untrackedCache=true
和GIT_FORCE_UNTRACKED_CACHE=1
,
这有助于更新未跟踪的缓存以提高git status
性能,时间约为4秒,这在大多数Stack Overflow答案中都有提到。
stack-overflow问题
但现在在Git 2.36.1版本中,这种解决方法似乎不起作用了。在所有分支上都需要大约20秒钟。
可能的代码更改:
在Git 2.35.1中,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);
}
}
在 Git 2.36.1 中,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);
}
}
编辑 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'.
当我切换分支并回到默认分支时,以下是性能情况。我不确定为什么下面的read-cache.c会占用这么多时间!
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:
….
编辑2:
我做了一些研究,发现当我设置 core.splitindex=true 时会创建 .git/sharedindex. 文件,并且 sharedindex 占用了时间。那么这与性能有关吗?
如何解决未跟踪文件缓存性能问题?有没有解决方法?