Performance boost with eventignore
tummetott opened this issue · 4 comments
Hey
When I define the following autocmd:
:autocmd WinScrolled * echom 'scrolled'
and then press <C-f>
, then scrolled
is printed ~40 times (this depends on the screen size of course)
I have several plugins installed which perform callbacks on the WinScrolled
event (like nvim-scrollbar
, indent-blankline.nvim
, feline.nvim
). Hence, every registered autocmd for this event is triggered ~40 times when pressing <C-f>
only once.
I've experimented with neoscrolls hooks and came up with the following configuration:
require('neoscroll').setup({
pre_hook = function()
vim.opt.eventignore:append({
'WinScrolled',
'CursorMoved',
})
end,
post_hook = function()
vim.opt.eventignore:remove({
'WinScrolled',
'CursorMoved',
})
end,
})
It has the effect that for every scroll (no matter which one), the CursorMoved
and WinScrolled
event are only fired once instead of many times. This reduces my CPU utilization significantly when scrolling.
Of course there are also side effects: My scrollbar (rendered by nvim-scrollbar
) or my line number indicator in the statusline (rendered by feline.nvim
) is e.g. only upated when the scroll animation finished. However this does not bother me at all since the performance is muuuuuuch better and i'm mostly looking at the code while scrolling.
I've seen that there already exists a performance mode in neoscroll.nvim
, which disables syntax highlighting. This tradeoff however is not for me. It makes me headache when the colors turn off and on 😄
So I'm opening this issue in case you're not aware of this trick. Maybe this can be added to the plugin and made configurable somehow? Otherwise i'll just keep it in my dots 🙂
Thanks for this! Added in nvim-scrollbar
and was appalled by the drop in performance. Almost uninstalled the plugin if not for this comment.
This is a great fix. I've noticed seemingly random lagginess on some files. Adding this in fixed that immediately and I get smooth scrolling.
Was this close to delete this plugin as it was NOT smooth in large files but this config made me continue use it. Thank you :)