From: Xing Xin <xing…@bytedance.com> Since ecbc23e4c5 (status: modernize git-status "slow untracked files" advice, 2022-11-30), the advice that "git status" gives when enumerating untracked files takes more than 2 seconds adds "but the results were cached, and subsequent runs may be faster" whenever core.fsmonitor is enabled. But it is the untracked cache that caches these results, with or without fsmonitor: - Without the untracked cache, which is off by default, every run enumerates all untracked files again, however fsmonitor is configured, and the promised speedup never comes. - With it, subsequent runs only read the directories that changed, which they find by checking the stat data of all directories, or, with fsmonitor, by asking it. In the Linux kernel repository, on an Apple M4 Pro, enumerating the untracked files takes 305ms when the untracked cache is created, then 17ms with the untracked cache alone, 9ms with fsmonitor as well, and still 313ms with fsmonitor alone. The documentation that ecbc23e4c5 added says as much: "While the FSMonitor feature can be enabled without the untracked cache, the benefits are greatly reduced in that case." But the code checks only core.fsmonitor. Give the remark when the untracked cache was used to enumerate the untracked files, whether fsmonitor is enabled or not. Checking core.untrackedCache instead would not be accurate either: the untracked cache is enabled but not used with "--ignored" or a pathspec, and with core.untrackedCache set to "keep", its default, the untracked cache is used if the index already has one. So record in struct wt_status whether dir.untracked is set after fill_directory(), as read_directory() resets it when it cannot use the untracked cache. Signed-off-by: Xing Xin <xing…@bytedance.com> --- status: base the "results were cached" remark on the untracked cache Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2345%2Fblanet%2Fxx%2Fstatus-untracked-cache-advice-v1 Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2345/blanet/xx/status-untracked-cache-advice-v1 Pull-Request: https://github.com/gitgitgadget/git/pull/2345 t/t7508-status.sh | 35 ++++++++++++++++++++++++++++++++++- wt-status.c | 6 +++--- wt-status.h | 1 + 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/t/t7508-status.sh b/t/t7508-status.sh index e10c961268..47fb48c9d0 100755 --- a/t/t7508-status.sh +++ b/t/t7508-status.sh @@ -1853,7 +1853,8 @@ test_expect_success 'slow status advice when core.untrackedCache true, but not f cat >expected <<-\EOF && On branch main - It took 3.25 seconds to enumerate untracked files. + It took 3.25 seconds to enumerate untracked files, + but the results were cached, and subsequent runs may be faster. See '\''git help status'\'' for information on how to improve this. nothing to commit, working tree clean @@ -1881,6 +1882,38 @@ test_expect_success 'slow status advice when core.untrackedCache true, and fsmon ) ' +test_expect_success 'slow status advice when fsmonitor, but not core.untrackedCache' ' + ( + cd slowstatus && + git config core.untrackedCache false && + git config core.fsmonitor true && + GIT_TEST_UF_DELAY_WARNING=1 git status >actual && + cat >expected <<-\EOF && + On branch main + + It took 3.25 seconds to enumerate untracked files. + See '\''git help status'\'' for information on how to improve this. + + nothing to commit, working tree clean + EOF + test_cmp expected actual + ) +' + +test_expect_success 'slow status advice when the untracked cache is not used' ' + ( + cd slowstatus && + git config core.untrackedCache true && + git config core.fsmonitor true && + GIT_TEST_UF_DELAY_WARNING=1 git status --ignored >actual && + test_grep "^It took 3.25 seconds to enumerate untracked files\.$" actual && + test_grep ! "results were cached" actual && + GIT_TEST_UF_DELAY_WARNING=1 git status -- .gitignore >actual && + test_grep "^It took 3.25 seconds to enumerate untracked files\.$" actual && + test_grep ! "results were cached" actual + ) +' + test_expect_success EXPENSIVE,SIZE_T_IS_64BIT 'status does not re-read unchanged 4 or 8 GiB file' ' ( mkdir large-file && diff --git a/wt-status.c b/wt-status.c index 238bb48643..0070140f12 100644 --- a/wt-status.c +++ b/wt-status.c @@ -34,7 +34,6 @@ #include "worktree.h" #include "lockfile.h" #include "sequencer.h" -#include "fsmonitor-settings.h" #define AB_DELAY_WARNING_IN_MS (2 * 1000) #define UF_DELAY_WARNING_IN_MS (2 * 1000) @@ -828,6 +827,8 @@ static void wt_status_collect_untracked(struct wt_status *s) setup_standard_excludes(&dir); fill_directory(&dir, istate, &s->pathspec); + /* read_directory() resets it if the untracked cache cannot be used */ + s->untracked_cache_used = !!dir.untracked; for (i = 0; i < dir.nr; i++) { struct dir_entry *ent = dir.entries[i]; @@ -1993,7 +1994,6 @@ static void wt_longstatus_print(struct wt_status *s) { const char *branch_color = color(WT_STATUS_ONBRANCH, s); const char *branch_status_color = color(WT_STATUS_HEADER, s); - enum fsmonitor_mode fsm_mode = fsm_settings__get_mode(s->repo); if (s->branch) { const char *on_what = _("On branch "); @@ -2052,7 +2052,7 @@ static void wt_longstatus_print(struct wt_status *s) wt_longstatus_print_other(s, &s->ignored, _("Ignored files"), "add -f"); if (advice_enabled(ADVICE_STATUS_U_OPTION) && uf_was_slow(s)) { status_printf_ln(s, GIT_COLOR_NORMAL, "%s", ""); - if (fsm_mode > FSMONITOR_MODE_DISABLED) { + if (s->untracked_cache_used) { status_printf_ln(s, GIT_COLOR_NORMAL, _("It took %.2f seconds to enumerate untracked files,\n" "but the results were cached, and subsequent runs may be faster."), diff --git a/wt-status.h b/wt-status.h index e9fe32e98c..894361efb4 100644 --- a/wt-status.h +++ b/wt-status.h @@ -145,6 +145,7 @@ struct wt_status { struct string_list untracked; struct string_list ignored; uint32_t untracked_in_ms; + int untracked_cache_used; }; size_t wt_status_locate_end(const char *s, size_t len); base-commit: acba8bf9753134d9bde89f94369f775838a8c5fe
-- gitgitgadget