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

cursor flickering issue #63

Closed
kkharji opened this issue Feb 25, 2022 · 24 comments
Closed

cursor flickering issue #63

kkharji opened this issue Feb 25, 2022 · 24 comments

Comments

@kkharji
Copy link

kkharji commented Feb 25, 2022

When ever a new notification is displayed the cursor flickers for the length of the message.

Reproduce lua vim.lsp.buf.code_action() on a buffer that doesn't support lsp.

@rcarriga
Copy link
Owner

Unfortunately I don't get any notification triggering the code action call in a non-lsp buffer. The previous issue was due to a slow SSH connection (AFAIK), is there anything similar about your setup that might cause stuttering on fast re-renders?

If you're willing to debug a little, you could try changing how frequently renders occur by editing this line https://github.com/rcarriga/nvim-notify/blob/master/lua/notify/service/init.lua#L25. Current setting is to render every 30ms

@kkharji
Copy link
Author

kkharji commented Feb 25, 2022

Hey @rcarriga , hmmm I tried playing around with the render and I'm pretty sure it's nothing todo with. The cursor flickering is the same.

Nope first time noticing this behavior.

I have this vim settings if relevant

vim.o.updatetime = 100
vim.o.redrawtime = 1500
vim.o.lazyredraw = true
vim.o.timeout = true
vim.o.ttimeout = true
vim.o.timeoutlen = 500
vim.o.ttimeoutlen = 10

Also I have these cursor related autocmds

CursorHold    ▏octo://*lua require'octo'.on_cursor_hold()                                         
CursorHold*lua require'octo.reviews'.show_review_threads()                            
CursorHold<buffer=4>      ▏ :silent! lua vim.lsp.buf.document_highlight()                              
CursorHold<buffer=5>      ▏ :silent! lua vim.lsp.buf.document_highlight()                              
CursorHold<buffer=3>      ▏ :silent! lua vim.lsp.buf.document_highlight()                              
CursorHold<buffer=2>      ▏ :silent! lua vim.lsp.buf.document_highlight()                              
CursorHold<buffer=8>      ▏ :silent! lua vim.lsp.buf.document_highlight()                              
CursorHold<buffer=5>lua require'nvim-treesitter-refactor.highlight_definitions'.highlight_usages(5)
CursorHold<buffer=3>lua require'nvim-treesitter-refactor.highlight_definitions'.highlight_usages(3)
CursorHold<buffer=2>lua require'nvim-treesitter-refactor.highlight_definitions'.highlight_usages(2)  
CursorHold<buffer=4>lua require'nvim-treesitter-refactor.highlight_definitions'.highlight_usages(4)  
CursorHold<buffer=8>lua require'nvim-treesitter-refactor.highlight_definitions'.highlight_usages(8)  
CursorHold<buffer=171>lua require'nvim-treesitter-refactor.highlight_definitions'.highlight_usages(171)
CursorHold<buffer=207>lua require'nvim-treesitter-refactor.highlight_definitions'.highlight_usages(207)
CursorHold<buffer=189>lua require'nvim-treesitter-refactor.highlight_definitions'.highlight_usages(189)

which I disabled but still

@rcarriga
Copy link
Owner

rcarriga commented Mar 1, 2022

So if you change the render to happen only once a second, that still flickers? If the render speed has no effect on the window flickering then I'll be very confused as otherwise it's just a regular floating window 😅

The cursor autocmds should have no effect, nvim-notify doesn't change cursor position

@gegoune
Copy link

gegoune commented Mar 30, 2022

Most likely related NeogitOrg/neogit#220 - still getting the same issue (on wezterm, without tmux or alacritty).

@gegoune
Copy link

gegoune commented Apr 4, 2022

@tami5 could you please confirm if flickering of cursor occurs when there is only single notification displayed? I have just noticed that it flickers for me only when there is more than one at the time.

@rcarriga
Copy link
Owner

rcarriga commented Apr 5, 2022

@gegoune Following on with NeogitOrg/neogit#220 (comment) I just realised i pointed you to the wrong line, you actually need to also change https://github.com/rcarriga/nvim-notify/blob/master/lua/notify/service/init.lua#L37 as well sorry 🤦

@gegoune
Copy link

gegoune commented Apr 5, 2022

Ah, now I see the difference! Set both to 500 and got that:

500.mov

But what might be even more important is the fact that with minimal renderer as well and blinking is completely gone.

@rcarriga
Copy link
Owner

rcarriga commented Apr 6, 2022

Ah OK so the flickering still happens but slowly which suggests it's a specific action causing the flickering, not just general rendering. If it doesn't happen for using the minimal renderer then my best guess would be something in the default renderer. Sorry I can't test myself since I can't reproduce but you could try removing some of the api calls to remove different parts of the rendering to try pinpoint what might be causing the issue.

If the difference doesn't happen for the minimal one could you also try using the slide stages option as that will disable opacity changes, which I think also stop the flickering

@gegoune
Copy link

gegoune commented Apr 6, 2022

Will try to bisect default renderer when I get a chance later today. Quickly tested stages ="slide" now and it still flickers (on default renderer).

@gegoune
Copy link

gegoune commented Apr 6, 2022

Did not have a chance to properly look into bisecting default renderer, tried quickly and was just erroring due to my edits. But what I discovered now is that flickering happens in wezterm even with minimal nvim configuration. But does not happen in terminal.app whether I use my full or minimal config. Also does not happen in kitty at all. I am sure when I first reported that issue I experienced it on alacritty. Perhaps that will allow you to replicate it? Can you think of why different terminals could behave differently?

rcarriga added a commit that referenced this issue Apr 7, 2022
Misc performance improvements (some inspired by
http://wiki.luajit.org/Numerical-Computing-Performance-Guide)

Major one is diffing the window configs before updating to avoid
unnecessary rendering.

Also switched to mutating existing state in spring rather than creating
a new table which reduces number of allocations (one per field window per
draw).

Should help #63 and potentially #72
@rcarriga
Copy link
Owner

rcarriga commented Apr 7, 2022

OK thanks for that I was able to reproduce with wezterm 😅 Definitely looks to be highly dependent on hardware and the terminal emulator as alacritty and kitty didn't show any for me.

Anyway I've added a few performance improvements but the main one avoids unnecessary rendering. It looks like it helps a lot with the flickering but doesn't eliminate it entirely. Unfortunately I think it would be impossible to guarantee there will never be any flickering since it depends on terminal/hardware.

@gegoune
Copy link

gegoune commented Apr 7, 2022

This is truly amazing! Works so much better already. I will run some more tests later but after quick look flicker seems to be gone! You rock!

@smithbm2316
Copy link

I can confirm that this seems to be gone in my version of Wezterm as well! Thank you for your timely updates on this particular issue @rcarriga and for your work in general on this plugin. It's such an amazing addition to my Neovim workflow 😄

@rcarriga
Copy link
Owner

rcarriga commented May 1, 2022

I'm probably going to close this unless someone has objections. This entire plugin abuses rendering NeoVim's rendering so as I said I don't think we'll ever get guaranteed perfect rendering and it seems like the worst of it is solved.

@gegoune
Copy link

gegoune commented May 1, 2022

Forgot to report back: would still get flicker on occasion but nothing major in terms of frequency. So good to close as far as I am concern.

Out of interest, what do you mean by saying "abuses vim's rendering"?

@rcarriga
Copy link
Owner

rcarriga commented May 1, 2022

I mean I don't think that NeoVim's rendering is designed to redraw multiple windows and redefining multiple highlights 30 times a second 😅 Though there are performance improvements being made by the core team (e.g. lua controlled highlights) that will continue to make it more performant

@rcarriga rcarriga closed this as completed May 1, 2022
@utkarshgupta137
Copy link

I'm still facing this issue. Changing the render option doesn't help. The only thing that helps is using static stage or lowering fps.
Hardware: MBP 14" (M1 Pro)
Term: Alacritty
NeoVim: v0.9.0-dev-1237+gaccdb0104 + AstroNvim v3.2.2

@rcarriga
Copy link
Owner

This is not something that will ever be 100% fixed, it's dependent on the performance of the terminal/GUI. Kitty seems to be the least problematic terminal.

Bowser1704 added a commit to Bowser1704/dotfiles that referenced this issue Mar 24, 2023
@utkarshgupta137
Copy link

This is not something that will ever be 100% fixed, it's dependent on the performance of the terminal/GUI. Kitty seems to be the least problematic terminal.

I've found alacritty to be faster than most terminals I've tried. I don't wanna switch to kitty (because it has a couple of missing features & the author can be very abusive when they're requested). Are there any vim/plugin settings you'd like me to try which can help with this issue? Or perhaps you know why kitty is more performant than alacritty in this case?

@rcarriga
Copy link
Owner

It's hard to pinpoint what will make the difference. The fps, stages and render are the
only settings you can alter within neovim to make a difference, unless you can
find some optimisations within the plugin that I haven't 😄

The underlying issue is just that nvim-notify works by constantly updating
window highlights and position. This is not something the API was originally
intended for and so it makes sense that it isn't perfect. As to why Kitty works
better here than Alacritty, I don't know I'm just basing that opinion off of
what I and others have seen.

@utkarshgupta137
Copy link

It's hard to pinpoint what will make the difference. The fps, stages and render are the only settings you can alter within neovim to make a difference, unless you can find some optimisations within the plugin that I haven't 😄

The underlying issue is just that nvim-notify works by constantly updating window highlights and position. This is not something the API was originally intended for and so it makes sense that it isn't perfect. As to why Kitty works better here than Alacritty, I don't know I'm just basing that opinion off of what I and others have seen.

I'm hoping alacritty/alacritty#5843 will reduce the issues.

@dgmora
Copy link

dgmora commented Apr 4, 2023

I can confirm as well that I had this problem with alactritty, but with kitty I don't. I had it with the default mac terminal as well.

@nikbrunner
Copy link

nikbrunner commented Jul 5, 2023

Just reporting in that I am having the same problem in Warp Terminal. When I use Kitty the flickering is gone.

@alecandido
Copy link

Only for the sake of reporting: same problem with iTerm2 on MacOS.

I don't care so much about smooth transitions, so I also set fps = 1, but it flickers at 1Hz. fps = 2 clearly doubles the frequency...

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

8 participants