On Thu, May 22, 2025 at 11:59 AM Kristoffer Balintona < krisbalintona@gmail.com> wrote: > On Thu, May 22 2025, Yikai Zhao wrote: > > > After enabling `project-mode-line`, I find my emacs slightly less > > responsive. I think it's because project-mode-line is slow due to > > it trying to read files on each update. Here's how I reproduce it: > > > > - Run `emacs -Q` > > - Evaluate `(setopt project-mode-line t)` > > - Open some random file in a non-project directory, e.g. `/tmp/test`, > > start typing > > > > Here's part of the profiling result: > > > > 114 62% - redisplay_internal (C function) > > 42 23% - eval > > 41 22% - project-mode-line-format > > 41 22% - project-current > > 41 22% - project--find-in-directory > > 41 22% - run-hook-with-args-until-success > > 41 22% - project-try-vc > > 41 22% - project-try-vc--search > > 25 13% - project--value-in-dir > > 22 12% - hack-dir-local-variables > > 22 12% - # > > 22 12% - hack-dir-local--get-variables > > 22 12% - dir-locals-find-file > > 22 12% - locate-dominating-file > > 12 6% + abbreviate-file-name > > 3 1% + # > > 13 7% - locate-dominating-file > > 6 3% + # > > 3 1% abbreviate-file-name > > 3 1% > > > > It shows that `project-mode-line-format` can take a significant portion > > of the redisplay time. It increases even more when the directory is deep > > or the disk is slow. > > > > IMO the performance of this function should be improved. > > > > I have two questions: > > > > 1. Is it possible to simply cache the result as buffer-local? > > 2. IIUC some of the file reading comes from `project--value-in-dir`, > > which opens a temporary buffer to load dir local variables. Why doesn't > > it simply read the variable value in the current buffer? > > > > I experienced similar, actually, on Nix where the Emacs source files, > having been built in the special Nix store, are somewhere deep under > /nix/store/. I suspected it was project.el trying to find a root. I > never got around to confirming it nor finding a fix. > I'm taking some time today to rework my approach rather than use advice. That was hacky, and good enough for personal use to scratch an immediate itch. If this comes out well, I'll propose a project.el patch and see what people think. Daniel, I'm not so sure about blocking all IO in mode-line updates. That sounds like it will surprise a lot of people. -Stephane