Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance boost with eventignore #80

Closed
tummetott opened this issue Feb 10, 2023 · 4 comments
Closed

Performance boost with eventignore #80

tummetott opened this issue Feb 10, 2023 · 4 comments

Comments

@tummetott
Copy link

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 🙂

@chrisvander
Copy link

chrisvander commented Feb 20, 2023

Thanks for this! Added in nvim-scrollbar and was appalled by the drop in performance. Almost uninstalled the plugin if not for this comment.

@karb94 karb94 pinned this issue Mar 4, 2023
@jrwrigh
Copy link

jrwrigh commented May 20, 2023

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.

@idelice
Copy link

idelice commented Sep 23, 2023

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

@karb94
Copy link
Owner

karb94 commented Sep 7, 2024

Neoscroll now provides a config option to ignore events while scrolling called ignore_events (:help neoscroll-options). By default it ignores WinScrolled and CursorMoved as I think most people will benefit from this. If you don't want any events to be ignored pass an empty table ({}) to ignore_events.

From my testing, even if you ignore WinScrolled and CursorMoved they will still trigger once likely due to a timing issue in Neovim's event loop between the last line scrolled and the reenabling of the events. I haven't found a way to prevent this but since triggering these events once per scroll is probably desirable I left it as it is and documented it in the docs. Let me know if you have any issues with this.

Lastly, I want to thank @tummetott for opening this issue and providing a solution which I used to implement this feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants