Skip to content
This repository has been archived by the owner on May 27, 2024. It is now read-only.

Neovim 0.9.1 hangs consuming 100% CPU #45

Open
r-vdp opened this issue Jun 2, 2023 · 8 comments
Open

Neovim 0.9.1 hangs consuming 100% CPU #45

r-vdp opened this issue Jun 2, 2023 · 8 comments

Comments

@r-vdp
Copy link

r-vdp commented Jun 2, 2023

Describe the bug

Since upgrading to neovim 0.9.1, I get random hangs where neovim hangs and consumes 100% CPU on one core for seconds before recovering.
I tried enabling and disabling plugins to find the culprit and it seems to be nvim-ts-rainbow2.

Steps to reproduce

I don't know yet how to trigger the issue, but it happened several times today (I upgraded neovim yesterday night).

Expected behavior

No hangs.

Config

require("nvim-treesitter.configs").setup {
  highlight = {
    enable = true,
    disable = function(lang, buf)
      local max_filesize = 100 * 1024 -- 100 KB
      local ok, stats = pcall(vim.loop.fs_stat, vim.api.nvim_buf_get_name(buf))
      if ok and stats and stats.size > max_filesize then
        return true
      end
    end,
  },

  rainbow = {
    enable = true,
    extended_mode = true,
    max_file_lines = 20000,
    query = {
      "rainbow-parens",
      html = "rainbow-tags",
      latex = "rainbow-blocks",
    }
  }
}
@HiPhish
Copy link
Owner

HiPhish commented Jun 2, 2023

Which file type does this happen with? Can you provide a sample text? BTW, you can remove extended_mode and max_file_lines from your configuration, they do nothing in this fork.

@KTheRD
Copy link

KTheRD commented Jun 5, 2023

I am using Astronvim with Lazy package manager, I added rainbow without any configuration like this:

return {
  "nvim-treesitter/nvim-treesitter",
  dependencies = {
    "HiPhish/nvim-ts-rainbow2",
  },
  opts = {
    rainbow = {
      enable = true,
    },
  },
}

Noticed some weird hangs when I edited some typescript, but they appeared rarely and I didn't do anything to solve them.
Recently I tried out Zig language and it hangs every time I open zig file and try to edit it (even empty .zig file). Tried to remove plugins from my config, removing rainbow fixes the problem, so I think the issue is in this plugin.

Neovim version is v0.10.0-dev (neovim-nightly from AUR); Lazy fetched e1783c8 commit of rainbow.

UPD: this fork https://github.com/mrjones2014/nvim-ts-rainbow works for me

@kiyoon
Copy link

kiyoon commented Jun 5, 2023

It doesn't hang for me but I see a noticeable slowdown. Also when I comment a block with comment.nvim or mini.comment, it takes 10 seconds. Uninstalling this plugin resolves the issue but also I think it's upstream neovim treesitter problem

@HiPhish
Copy link
Owner

HiPhish commented Jun 5, 2023

@KTheRD Zig is a problem in general, see #43 for my findings. It is the query file itself that causes Neovim to hang for a bit every time you open your first Zig file. Even when using the no-op strategy (:h ts-rainbow.strategy.noop) the editor will freeze. After you have opened the first Zig file everything should be smooth again.

The fork you have linked works differently, it has very naive queries. These cause more problems than they solve, it is impossible to reliably determine the level of nesting for every file type and every strategy. But I guess if it works for you, then good for you.

@HiPhish
Copy link
Owner

HiPhish commented Jun 5, 2023

@kiyoon Can you please provide a file where this happens? I tried comment.nvim and commenting out a block was instantaneous. Do you have any other Tree-sitter modules enabled as well?

@kiyoon
Copy link

kiyoon commented Jun 5, 2023

@HiPhish If you're interested, I reported the summary of finding here

neovim/neovim#23918

@HiPhish
Copy link
Owner

HiPhish commented Jun 5, 2023

I would still like a sample file so I can try to replicate the problem. It could very well be on my side because after every change to the tree I have to re-compute the tree structure of delimiters.

One thing you can try is to set the strategy to the no-op strategy (:h ts-rainbow.strategy.noop). The no-op strategy does nothing, so if you still get slowdowns that's a good indicator that the problem might be on the Neovim side.

rainbow = {
	enable = true,
	strategy = {
		rainbow.strategy.noop,
	},
},

@HiPhish
Copy link
Owner

HiPhish commented Jul 3, 2023

This plugin is now deprecated because of upcoming changes to nvim-treesitter. The new rainbow plugin is here: rainbow-delimiters.nvim (GitHub mirror). Please file an issue over there if the problem still persists.

blurgyy added a commit to blurgyy/flames that referenced this issue Jul 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants