nvim-telescope / telescope.nvim

Find, Filter, Preview, Pick. All lua, all the time.
MIT License
15.97k stars 838 forks source link

`find_files` is way slower than fzf.vim for huge directories #2884

Closed vegerot closed 9 months ago

vegerot commented 9 months ago

demo

Description

In huge directories, Telescope's find_files is much slower than fzf.vim's :Files.

I have reproduced this on Telescope's master and 0.1.5. With and without fzy, and with and without previews enabled for both :Files and :Telescope find_files.

Neovim version

NVIM v0.10.0-dev
Build type: Release
LuaJIT 2.1.1703358377

Operating system and version

macOS 14.2.1

Telescope version / branch / rev

reproduced on both d909568 (0.1.5) and 20efb3 (master)

checkhealth telescope

telescope: require("telescope.health").check()

Checking for required plugins ~
- OK plenary installed.
- OK nvim-treesitter installed.

Checking external dependencies ~
- OK rg: found ripgrep 14.1.0
- OK fd: found fd 9.0.0

===== Installed extensions ===== ~

Telescope Extension: `fzy_native` ~
- No healthcheck provided

Steps to reproduce

  1. install telescope.nvim
  2. install fzf.vim
  3. export FZF_DEFAULT_COMMAND=fd
  4. (optional) use my init.vim
  5. visit HUGE repo (I used chromium/third_party/blink)
  6. run :Telescope find_files and search for a file
  7. run :Files and search for a file

Expected behavior

:Telescope find_files should take about as long as :Files

Actual behavior

:Telescope find_files takes about 10x longer than :Files

Minimal config

-- idk how to use packer or init.lua
-- a non-minimal configuration is at https://github.com/vegerot/dotfiles/blob/master/.config/nvim/init.vim

vim.cmd [[set runtimepath=$VIMRUNTIME]]
vim.cmd [[set packpath=/tmp/nvim/site]]
local package_root = '/tmp/nvim/site/pack'
local install_path = package_root .. '/packer/start/packer.nvim'
local function load_plugins()
  require('packer').startup {
    {
      'wbthomason/packer.nvim',
      {
        'nvim-telescope/telescope.nvim',
        requires = {
          'nvim-lua/plenary.nvim',
          { 'nvim-telescope/telescope-fzy-native.nvim', run = 'make' },
        },
      },
      'junegunn/fzf.vim',
    },
    config = {
      package_root = package_root,
      compile_path = install_path .. '/plugin/packer_compiled.lua',
      display = { non_interactive = true },
    },
  }
end
_G.load_config = function()
  require('telescope').setup()
  require('telescope').load_extension('fzy_native')
  -- ADD INIT.LUA SETTINGS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
end
if vim.fn.isdirectory(install_path) == 0 then
  print("Installing Telescope and dependencies.")
  vim.fn.system { 'git', 'clone', '--depth=1', 'https://github.com/wbthomason/packer.nvim', install_path }
end
load_plugins()
require('packer').sync()
vim.cmd [[autocmd User PackerComplete ++once echo "Ready!" | lua load_config()]]
jamestrew commented 9 months ago

Indeed it is. This might be a bit outdated but here's a comparison between fzf.vim and telescope outlining the reasons/compromises. https://github.com/nvim-telescope/telescope.nvim/issues/719#issuecomment-812879771

If you're frequently working on large codebases and/or have limited hardware, Telescope's find_files may not be for you.

fzf.vim or fzf-lua are still great tools especially if performance is a concern.

We hope to improve on this more but I don't think it's likely that we'll ever fully catch up to these alternatives in terms of performance.

tankorsmash commented 2 months ago

Hey,

Telescope is very pretty, and seems useful, but in case anyone else runs into Telescope being slower than you'd expect. It seems like disabling the preview is the quickest gain.

For context, I'm using CtrlP (with PyMatcher and fd as the user command (let g:ctrlp_user_command = 'fd --type f --color=never --exclude "**/*.jar" --exclude "**/*.png" . %s')), and it's also much faster than find_files even on a 633 file project (according to fd | wc -l), and just as bad on a 11k file project.

Since Telescope uses Nvim's builtin LSP, it can't talk to coc.nvim either, so the telescope.lsp_*/diagnostics things can't work either.

Is there maybe a common list of other settings to tweak to improve performance? It seems like disabling the file preview has the largest impact because of my slow LSPs,

:lua require('telescope.builtin').find_files({previewer=false})
" or
:Telescope find_files previewer=false

Most of my files have the 'previewer timed out' error, so I guess it's not a telescope specific issue after all, but it's a shame.

Hope this helps anyone else trying to get instant search results; disabling preview is the way to go.

vegerot commented 2 months ago

@tankorsmash jooc after making these changes, is find_files even within an order of magnitude of fzf.vim for performance?

tankorsmash commented 1 month ago

Oh, I thought "jooc" was a mis-ping, instead of maybe 'just out of curiosity'! I don't use fzf.vim, but without previewing, it's about comparable to CtrlP without custom matchers. Hadn't tried since the comment a few weeks ago.

I'm back to CtrlP with instant results though!