MaartenStaa / file-web-devicons

Prepends filetype icons to paths read from stdin
3 stars 1 forks source link

The reason you're having a delay in files showin up in large repos #4

Open ibhagwan opened 1 month ago

ibhagwan commented 1 month ago

Hi,

I became aware of this repo due to https://github.com/ibhagwan/fzf-lua/discussions/1188.

From your README (and the motivation for the above issue):

I found that, in large Git projects, fzf-lua's default files provider would have a delay of several seconds before files would show up

This doesn't happen due to the icons being slow to load, this happens due to the defaults using git_icons=true (adding M next to modified files, etc), unfortunately this requires having to wait for git status -sb to end before being able to start the file enumeration.

However simply running the below should solve the issue:

:FzfLua files git_icons=false

Disabling just for files:

require("fzf-lua").setup({
  files = { git_icons=false },
})

Disabling globally:

require("fzf-lua").setup({
  defaults = { git_icons=false },
})

Btw, since even the author of mini.nvim wasn't aware of this: https://redlib.freedit.eu/r/neovim/comments/1coyfk0/slowly_switching_almost_everything_to_mininvim/l3kehut/

I've since added a warning if the initial git status takes longer than 3s: https://github.com/ibhagwan/fzf-lua/blob/7109a18dd1832703209fc8f46e85df3c6ed6d059/lua/fzf-lua/make_entry.lua#L79-L80

MaartenStaa commented 1 month ago

Hey @ibhagwan, thanks for reaching out and pointing out the git_icons flag! That definitely makes a noticeable difference, estimating about 0.5s slower to load versus raw fd and piping the results through this binary.

The difference does start to become much more obvious when toggling the ignore flag, to be able to search for files in e.g., node_modules as well. In my (not very scientific) test just now, the results were:

The latter for some reason also shows about 100k files extra (for just over 300k files total), probably due to the --hidden flag, so presumably the actual difference in performance is bigger than this.

So for very large repositories, I think this project is still very much worth it, but for smaller projects simply disabling git_icons would be a perfectly acceptable setup for most people, I think.

(Also, now that I realize there's a git_icons flag, I realize it's missing from my current setup. I may add an option for that to this project in the future)

Again, thanks for reaching out, and thanks as well for your great work on fzf-lua, I'm very happy to use it every day 🙂

ibhagwan commented 1 month ago

Hi @MaartenStaa 👋

:FzfLua files git_icons=false, followed by ctrl-g, takes about 6–7 seconds to load all files (total file counter stops increasing)

Although I would suspect better performance piping through a rust iconifier vs a neovim lua wrapper 6-7 seconds (potential more, as you mentioned) sounds a bit too much, perhaps there are other factors making it not so much as “apples to apples” (same exact command, etc).

Fzf-lua also has to account for multi part extensions (such as foo.test.jsx, etc), path shortening, path formatting / beatification (file first, home to ~, etc) which do add some more overhead.

As long as you’re happy with your solution we don’t need to explore this further, it’s a great side project to have :)

ibhagwan commented 1 month ago

Btw, if you haven’t seen this https://github.com/coreyja/devicon-lookup you might get some nice ideas for your project, it also has a nice write up about the optimization process: https://coreyja.com/posts/vim-fzf-with-devicons.