RRethy / vim-illuminate

illuminate.vim - (Neo)Vim plugin for automatically highlighting other uses of the word under the cursor using either LSP, Tree-sitter, or regex matching.
2.19k stars 50 forks source link

nvim freezes when opening large c files #135

Closed menash134 closed 2 years ago

menash134 commented 2 years ago

Describe the bug opening a large file results in high cpu usage of nvim and freeze

To Reproduce

minimal init.vim if empty(glob('~/.config/nvim/autoload/plug.vim')) silent !curl -fLo ~/.config/nvim/autoload/plug.vim --create-dirs \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim endif

call plug#begin('~/.config/nvim/autoload/plugged')

Plug 'nvim-treesitter/nvim-treesitter' Plug 'RRethy/vim-illuminate'

call plug#end()

Steps to reproduce the behavior (include minimal init.vim or .vimrc): open https://elixir.bootlin.com/linux/v4.4.302/source/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_n.c in nvim Edit the file by typing "#define" or some random text and save the file Scroll down See CPU usage and neovim stuck with 100% cpu usage.

Note Omitting a minimal init.vim/init.lua/.vimrc will likely result in the issue being closed without explanation.

Output from :IlluminateDebug buf_should_illuminate 1 true config { delay = 100, filetype_overrides = {}, filetypes_allowlist = {}, filetypes_denylist = { "dirbuf", "dirvish", "fugitive" }, modes_allowlist = {}, modes_denylist = {}, providers = { "lsp", "treesitter", "regex" }, providers_regex_syntax_allowlist = {}, providers_regex_syntax_denylist = {}, under_cursor = true } started true provider table: 0x7f801c108d50 treesitter

Expected behavior nvim freezing and high cpu usage should not happen

Additional context somehow it is linked with treesitter. I tried treesitter alone, there is no problem.

Hope fully this time, as a newbie, I raised the issue correctly with all the information you need.

RRethy commented 2 years ago

I tried a few things out but there's no great solution to this, at the end of the day tree-sitter is going to be slow at running queries on large files (especially with the type of queries that run in vim-illuminate). There's a few strategies you can use to mitigate things:

RRethy commented 2 years ago

I'm going to close this because the most recent couple of commits are probably the most that can be done for this. It's tempting to try to only highlighting the window viewport but this has a lot of issues and likely wouldn't work. Try a config along these lines:

require('illuminate').configure({
    large_file_cutoff = 10000,
    large_file_overrides = {
        providers = { 'regex' },
        delay = 500,
        modes_allowlist = { 'n' },
    },
})
menash134 commented 2 years ago

Thanks for the workaround. I will try it and let you know.