noice.nvim icon indicating copy to clipboard operation
noice.nvim copied to clipboard

Using noice with galaxyline makes nvim heavily eat CPU

Open msva opened this issue 1 year ago ā€¢ 5 comments

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

msva avatar Oct 28 '22 05:10 msva

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 avatar Oct 28 '22 06:10 folke

Related:

  • [ ] https://github.com/neovim/neovim/issues/14303
  • [ ] https://github.com/neovim/neovim/issues/17937

folke avatar Oct 28 '22 06:10 folke

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

folke avatar Oct 28 '22 06:10 folke

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

folke avatar Oct 28 '22 06:10 folke

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)

msva avatar Oct 30 '22 13:10 msva

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

nanozuki avatar Nov 07 '22 15:11 nanozuki

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

folke avatar Nov 07 '22 15:11 folke

@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:

msva avatar Nov 07 '22 17:11 msva

Related:

  • [ ] https://github.com/neovim/neovim/issues/14303
  • [ ] https://github.com/neovim/neovim/issues/17937

See these issues

folke avatar Nov 07 '22 17:11 folke

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 ;)

msva avatar Nov 07 '22 17:11 msva

@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.

nanozuki avatar Nov 08 '22 02:11 nanozuki