Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Freezes on single line files, ignoring preview timeout #3032

Closed
pejrich opened this issue Apr 7, 2024 · 3 comments
Closed

Freezes on single line files, ignoring preview timeout #3032

pejrich opened this issue Apr 7, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@pejrich
Copy link

pejrich commented Apr 7, 2024

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()]]
@pejrich pejrich added the bug Something isn't working label Apr 7, 2024
@jamestrew
Copy link
Contributor

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.

@qmn1711
Copy link

qmn1711 commented Jul 29, 2024

Somehow, filesize_limit didn't work with a single large file 922 KB. I tried with { filesize_limit = 0.5555 } but telescope still froze ~30s and ignored preview timeout

@jamestrew
Copy link
Contributor

@qmn1711 it appears to be working for me using with telescope config

require("telescope").setup({
  defaults = {
    preview = {
      filesize_limit = 0.5555,
    },
  },
})

If it's still not working for you, can you open another issue with more details?

I'm going to close this issue as I don't know if there's anything we can do about the original issue besides restricting the previewer via other means like I mentioned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants