junegunn / fzf.vim

fzf :heart: vim
MIT License
9.51k stars 581 forks source link

`:Tags` is very slow on large tags file #1524

Closed nvincent-vossloh closed 3 months ago

nvincent-vossloh commented 4 months ago

Hello,

Thanks for your beautiful tools :slightly_smiling_face:

I have some repositories with larges tags file (130MB, few gigabytes) and when I use the Tags command to jump to the definition of a function, it takes a few seconds to process (up to 15 seconds on the linux sources ).

I had a quick look at the fzf#vim#tags function, and it looks like calling the tags.pl script takes quite some time (on large tags file). I replaced the tags.pl with the following:

#!/usr/bin/sed -f
/^!/d
s/$/tags/

(tested only with a single tags file located at the root of my sources folder from where I open vim). It is better, but still takes some time (compared to native tjump). Then I tried to modify fzf#vim#tags to use cat and s:tags_sink to make up for it, it still takes 7-8 seconds to load something, while tjump is instantaneous (tags file size is 1.2GB)

I have reproduced the behavior with minimal vim configuration.

Do you have any idea on how to improve response time of tags search ?

junegunn commented 4 months ago

The current implementation of :Tags can never be as fast as tjump.

tjump knows that the tags file is sorted by the symbols, so it can quickly binary-search for the specified symbol. The size of the tags file doesn't matter much.

On the other hand, :Tags reads through the whole tags file and loads everything on memory so that fzf can interactively search for any string on the line, not just the symbols. It will not work well with large tags files.

One thing we can try is to use readtags to pre-filter the list and feed the only matching lines to fzf on :Tags PREFIX.

readtags -t tags -p - prefix | fzf --query prefix --select-1