nvim-telescope/telescope.nvim

Freezes on single line files, ignoring preview timeout

pejrich opened this issue · 1 comments

Description

If I'm searching for a file, my Telescope will frequently lock up. I have quite a number of 5-20MB JSON files in the project. If the search query ever causes one of these files to be the top sorted result, my nvim would freeze for about 10-20 seconds. I tried adding preview timeout, no luck. I've just made the connection that it's specifically on single line files that it locks up. If I format the file that was giving me issues, then trying the same keystrokes again in Telescope find_files will correctly trigger the "previewer timed out". But for unformatted, single-line files, it freezes the whole nvim considerably.

Neovim version

NVIM v0.9.5
Build type: Release
LuaJIT 2.1.1703358377

Operating system and version

macOS 14.0

Telescope version / branch / rev

latest

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: `file_browser` ~
- No healthcheck provided

Telescope Extension: `fzf` ~
- OK lib working as expected
- OK file_sorter correctly configured
- OK generic_sorter correctly configured

Telescope Extension: `ui-select` ~
- No healthcheck provided

Steps to reproduce

  1. download this directory of 2 3mb dummy json files(plus some empty files). Open Telescope find_files, move the selection up and down. Once you hit the unformatted file, Telescope will freeze for a few seconds, and even when you're no longer selecting that file, Telescope still lags.
  2. Format the unformatted file, or duplicate the formatted file. Now we have roughly the same total amount of data, but this time Telescope is buttery smooth the whole way through.
    telescope_bug.zip

In this demo the delay is shorter as I didn't think you'd want some huge files, so these are only 3MB, but it should be enough to demonstrate the issue. When the files get up above 10-20MB, it's unresponsive for a good 10+ seconds.

Expected behavior

The previewer should timeout out without freezing nvim.

Actual behavior

The previewer takes a few seconds to timeout.

Minimal config

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-fzf-native.nvim', run = 'make' },
        },
      },
      -- ADD PLUGINS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
    },
    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('fzf')
  -- 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()]]

Hey, yeah so unfortunately, I don't think there's a great way to do true timeouts in Lua as we don't have preemptive multithreading. Our current implementation of the timeout is based on time between iterations of line splitting. So in cases like yours, where you have a large file with few lines, you can exceed the timeout period potentially significantly.

You can use the preview = { filesize_limit = <some value in MB> } } option to help with these larger files though. The filesize_limit check comes before the timeout check. Our default is 25MB.