fzf-lua icon indicating copy to clipboard operation
fzf-lua copied to clipboard

Question: preview lags

Open kapral18 opened this issue 1 year ago • 2 comments

Both grep and fd previews choke on big text files sometimes taking 5 to 15 seconds to unfreeze in the picker preview. While with vanilla fzf it's still choking but much more responsive so I was wondering how does the preview work do you use your own preview with treesitter or do you use the fzf vanilla preview coloring?

What is the best practice to speed previews up for large files bigger than 500kb for example giant .map or .json files, Given that I don't want to fully hide them I still want to be able to find the text in the preview with rg or see the output with fd?

Thanks

my config https://github.com/kapral18/config.nvim/blob/7f87d49990a0a3034da365c550f8a574a7d33f22/lua/plugins/fzf.lua

my fzf config:

# FZF
set FD_OPTIONS "--hidden --follow"
set -gx FZF_DEFAULT_OPTS "--no-mouse --height 80% --reverse --multi --info=inline --preview='bat {} --color always' --preview-window='right:60%:wrap' --bind=ctrl-d:half-page-down,ctrl-u:half-page-up,ctrl-b:page-up,ctrl-f:page-down"
set -gx FZF_DEFAULT_COMMAND "git ls-files --cached --others --exclude-standard 2>/dev/null || fd --type f --type l $FD_OPTIONS"
set -gx FZF_CTRL_T_COMMAND "$FZF_DEFAULT_COMMAND"
set -gx FZF_ALT_C_COMMAND "fd --type d $FD_OPTIONS"

alias fzfi='git ls-files --cached --others --exclude-standard 2>/dev/null || fd --type f --type l $FD_OPTIONS'

P.S. if this question is not appropriate in issues, I'd appreciate if you could open discussions so that these types of questions could be asked there.

kapral18 avatar Jan 29 '24 14:01 kapral18

While with vanilla fzf it's still choking but much more responsive so I was wondering how does the preview work do you use your own preview with treesitter or do you use the fzf vanilla preview coloring?

You can’t compare the default previewer to vanilla fzf, fzf-lua defaults uses a neovim buffer to load the file and also apply treesitter highlighting (which is what is most impacting performance), if you want to have a similar experience to vanilla fzf, use the bat previewer instead (or try the max_peformance or fzf.vim profiles).

What is the best practice to speed previews up for large files bigger than 500kb for example giant .map or .json files, Given that I don't want to fully hide them I still want to be able to find the text in the preview with rg or see the output with fd?

Take a look at the default previewer options: https://github.com/ibhagwan/fzf-lua/blob/14d34705906e979d94d8033953d40c64d2d96d02/lua/fzf-lua/defaults.lua#L189-L195

My suggestions:

  • Add a syntax limit either by number of lines syntax_limit_l or file size syntax_limit_b (bytes) - without syntax the files that meet this criteria will have no syntax coloring, the performance difference is quite big.

  • Experiment with what it means to disable treesitter for the preview and perhaps (either fully or for specific extensions), without treesitter you’d still have syntax coloring but just the “basic”, treesitter requires a lot of heavy lifting.

  • Finally if the files are too big for the previewer you can disable preview completely for large files with limit_b.

ibhagwan avatar Jan 29 '24 16:01 ibhagwan

thanks for the cues I will try those out

kapral18 avatar Jan 29 '24 16:01 kapral18

ok I basically switch off both syntax and treesitter, and I still have the same lags. I was previously using bat before switching to default because of some other issue I can't remember that bat was not supporting. I probably discussed this in another thread I need to find somewhere. But basically when I search with vanilla fzf what I see is that I can freely switch files without any delay even if in preview the render is stuck due to huge size. Is it achievable within fzf-lua?

kapral18 avatar Feb 01 '24 20:02 kapral18

I can’t control how neovim behaves when you open a large buffer, if you want the same experience as fzf.vim use bat, if you have issues with bat, open an issue and I’ll fix it.

ibhagwan avatar Feb 01 '24 21:02 ibhagwan

a tiny offtop @ibhagwan how can I enable highlight of current preview line for bat

          bat = {
            cmd = "bat",
            args = "--style=numbers,changes --color never --highlight-line={?}",
          },

kapral18 avatar Feb 01 '24 23:02 kapral18

a tiny offtop @ibhagwan how can I enable highlight of current preview line for bat

          bat = {
            cmd = "bat",
            args = "--style=numbers,changes --color never --highlight-line={?}",
          },

Why aren’t you using fzf-lua’s bat previewer?

Either set winopts.preview.default = “bat” or run :FzfLua files previewer=bat - it takes care of everything for you highlight lines included, previews for tags, buffers, etc.

ibhagwan avatar Feb 02 '24 01:02 ibhagwan

Run :FzfLua profiles and test fzf-native, max-perf and fzf.vim, they all use bat previewer.

You can use a profile as a base for your setup too: https://github.com/ibhagwan/fzf-lua?tab=readme-ov-file#profiles

fzf-native automatically sets previewer to bat (with line highlights) IMG_1853

ibhagwan avatar Feb 02 '24 01:02 ibhagwan

indeed setting everything bat solved the problem. Thanks

kapral18 avatar Feb 05 '24 17:02 kapral18