folke / noice.nvim

šŸ’„ Highly experimental plugin that completely replaces the UI for messages, cmdline and the popupmenu.
Apache License 2.0
4.16k stars 95 forks source link

Using noice with galaxyline makes nvim heavily eat CPU #144

Closed msva closed 1 year ago

msva commented 1 year ago

Describe the bug I didn't yet investigate this fully, and not yet found exact source of problem, but having both noice and galaxyline enabled makes nvim heavily eat CPU by producing tons of galaxyline's activity. Even with empty galaxyline config, it produces tons of epoll's, which noticeably loads CPU, and if there is some configuration, it can take about 40% CPU. And if there is git-related stuff, it can take up to 80-100% CPU out of nothing.

Disabling either galaxyline or noice leads to normal behavior (wihtout epoll_* spamming in strace).

I guess that it is related to noice functionality of "removing" bottom (command) line. And I guess it somehow make statusline (at least galaxyline) to rerender many times per second, which, in turn, leads to such behaviour...

Not sure, how to fix that, tho...

It should reproduce even with "empty" galaxyline config (although CPU load would be relatively smaller than with "informative" setups), and it should be possible to notice difference in nvim behaviour with and without strace.

But, just in case, my galaxyline config and my noice config.

With either of them disabled, neovim makes almost no syscalls, while user doesn't make any input, whatever would be opened there. But when both enabled, and any file opened (from everywhere, even /tmp, but, say, if it is lua/go files in git repo things goes worse), there are tons getcwd's, stats/openat's and so on. Thousands on them. And so CPU load jumps to high values...

Which version of Neovim are you using? TUI, v0.9.0-dev-69-g26c653718-dirty

folke commented 1 year ago

I've looked into this and there seems to be a problem with timers and galaxyline.

Instead of setting up Noice, add the following:

local timer = vim.loop.new_timer()
timer:start(0, 30, vim.schedule_wrap(function() end))

This will also spike CPU in a similar way, while it's doing nothing.

I don't have this problem with lualine.

folke commented 1 year ago

Related:

folke commented 1 year ago

It's a Neovim issue, but Galazyline can fix it by throttling statusline updates. I assume that's what lualine is doing.

folke commented 1 year ago

You can also set config.throttle for Noice to a higher value.

msva commented 1 year ago

You can also set config.throttle for Noice to a higher value.

By the way, it doesn't solve issue, even with higher values, just slightly decreases CPU load :cry:

So, looks like, the only way is to wait until issue will be somehow resolved upstream, or try to ask @gleipnir to add some lind of throttling in galaxyline (as even empty config adds tons futex'es in strace, and some CPU load), and it's modules (as, say, git-related ones search for git directory on every statusline update).

(Unfortunately, going to lualine is not a way I'd like to solve that, as it is less configurable (in the meaning of the components) than galaxyline, IMHO)

nanozuki commented 1 year ago

I use feline, and I have also observed this issue.

folke commented 1 year ago

@nanozuki it's an upstream issue, but can be also fixed in feline. Or use lualine.

msva commented 1 year ago

@folke unfortunately, lualine is not as customisable as galaxyline (or heirline. I already tested even with it).

Btw, I checked, and there is still a lot of spam in strace output even with lualine :shrug:

And also, there is possible to decrease CPU usage to 5%-ish by the price of higher values of throttling in noice, but it doesn't still save of multple-times-per-second statusline spamming.

// Also, it seems, tree-sitter also contributes to statusline spamming and CPU hanging, but it is harder to catch it's hand because of that situation :cry:

folke commented 1 year ago

Related:

See these issues

msva commented 1 year ago

Related:

See these issues

If it is for me, than I know that already (I even tried to poke nvim chat in matrix for that, but nobody cared :grinning:).

I just commented about lualine + some thoughts ;)

And if that's for @nanozuki, then nevermind ;)

nanozuki commented 1 year ago

@folke Yes, I read the discussion before. I want to mention the feline user who wants to find some information. Sorry for not explaining this clearly.

folke commented 1 year ago

Closing this, since it's an upstream issue