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
fix: Completely event driven update loop #2167
Conversation
The handler need to be send + sync + clone, and that's not the case on all platforms.
I'm not sure if im doing something wring but I tried this:
No blinking |
You need all three values: https://neovim.io/doc/user/options.html#'guicursor'
I implemented it according to that specification |
Awesome, now it works!
|
@9mm, since this also changes how the event loop is run, could you also test if it makes any difference when you run with vsync? |
I'm getting what I believe is the same issue as #2162, so I've just tried this branch to see if it fixes it. The easiest symptom to spot is that animations are "delayed" after being idle, sometimes to the point of being cut off entirely, meaning that the cursor "teleports" to its new location. It seems like Neovide is realising it should be animating the movement way too late - which fits perfectly with "rendering having to wait for the neovide_refresh_rate_idle wakeup". As suggested in #2162 (comment), I set On this branch, the issue is almost entirely gone, but not entirely. When using the keyboard to navigate, everything is good. But when using a mouse to click, the animations are still sometimes a bit delayed. Not always, but it is still happening. I've included three screen recordings below which I hope demonstrate the issue: on the latest On the latest
|
I think I've discovered why the mouse seems to trigger it on this branch but the keyboard doesn't. When using the keyboard, the noshowcmd.mp4 |
On OSX on this PR i get the same performance as before, so I'd say that's good. It may be even slightly better but it's hard to tell, it is definitely not worse though. |
@AThePeanut4, I don’t have those problems on my system with wayland. And it’s hard to tell without actual profiling data. |
That is, don’t take this branch when neovide/src/window/update_loop.rs Line 175 in aeaab02
|
I made this change: diff --git a/src/window/update_loop.rs b/src/window/update_loop.rs
index b67147a..cab0449 100644
--- a/src/window/update_loop.rs
+++ b/src/window/update_loop.rs
@@ -172,7 +172,7 @@ impl UpdateLoop {
Ok(Event::AboutToWait) | Err(false) => {
self.should_render.update(window_wrapper.prepare_frame());
if self.should_render == ShouldRender::Immediately || !self.idle {
- if window_wrapper.vsync.uses_winit_throttling() {
+ if self.num_consecutive_rendered > 0 && window_wrapper.vsync.uses_winit_throttling() {
window_wrapper.windowed_context.window().request_redraw();
} else {
self.render(window_wrapper); but it didn't appear to make a difference unfortunately. FYI, my system info:
I've attached tracy captures, one with the change above (latency_change.tracy.gz) and one without (latency.tracy.gz), following these instructions from #2162 (comment):
I hope they're useful - please let me know if you need me to do anything else. |
@AThePeanut4, thanks for the traces. I can definitely see a change between those two captures. I reduces the latency, but it's probably not the latency you are seeing, since it's at most one frame at 120 FPS, so 8ms. The changed versions renders as soon as the data is received from Neovim, which makes me think that the the latency is something else. I added some more profiling that should allow us to determine the exact delay from the input until it's rendered. But there's some delay until it's shown on the screen out of our control (the compositor and graphics pipeline). @AThePeanut4, so it would be great if you could take new captures. BTW, interestingly hyprland seem to reduce the frame rate to 60 FPS when the window is not active. Which could mess a bit with the frame dt detection we currently have, but I don't think that's the main problem here. |
I changed this to draft, while figuring out the problems and cleaning up the code a bit. |
I was able to repeat it, and I think it should be fixed now. There was a bug in the latency optimization, it did not request a new frame from wayland. So it was waiting until the idle frame rate had passed or another event from winit was received. And key up is such an event, so that explains why it glitches less when you release the key immediately. If |
@fredizzimo Can confirm it is now fixed. Thanks again! |
6f99799
to
5c973aa
Compare
@AThePeanut4. I actually force pushed a slightly different fix now. The previous fix could render an extra frame in some cases. But I think the result should be the same. |
This ensures that subsequent frames are rendred if needed
5c973aa
to
e34d9d9
Compare
That fix was also slightly wrong.. Time to go to bed. |
Hm.. I think something else is broken now.. the scrolling is not smooth |
@AThePeanut4, that was actually your configuration that I still had enabled by mistake. I'm not sure how to solve that, I think we need some kind of filtering, but that also adds some latency. And predictive solutions can be wrong. |
@fredizzimo Can confirm that on e34d9d9 the command mode animation issue and the initial issue are both still fixed. As for the scroll animation length, I think I understand what you mean (I'm holding down Perhaps animations could be different when holding keys down, if that's something that would even be possible. Maybe a different animation type (something more linear, perhaps?) or just a different animation length. That would be a separate feature request though - I wouldn't exactly call the current behaviour a bug. |
@@ -146,23 +144,23 @@ fn setup() -> Result<(WindowSize, NeovimRuntime)> { | |||
// Neovide also includes some other systems which are globally available via lazy static |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I believe the only remaining lazy static is settings? Maybe this can be reworded to not imply that there are multiple
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added documentation for the running tracker, which is still remaining.
made with `cargo fix`
I got this backtrace, im 90% sure it was when using this branch. Not sure if this is directly related though, I dont remember what I did i just know neovide froze for a long time and i had to force quit it, then i noticed it was there like i said though, its never happened any other time, and neovide never crashes, so might not be worth trying to chase down |
@9mm. I don't think it's related to this, but by studying the code there appears to be a bug where it will crash like that if you drag the window on top of a window that is closed while dragging. It would probably be better to report a new issue, and also check if you can repeat it like that. You probably need some window that autocloses with mouse actions. |
One suggestion is to animate the cursor blink, such as vsocde 2023-12-17.12-34-21.mp4 |
This is a reasonable feature request but likely out of scope for this PR |
@MOldtime if you were interested in contributing such a change, I'd be happy to give pointers for how to do it. I dont think itd be too hard. First step would be to make an issue with the feature request to discuss further |
Thank you for your kindness. This is a great project, but I don't have the experience of developing Rust. I decided to learn. Rust looks like many advantages. This takes a while |
This PR has almost solved my issue with Neovide fully utilizing single core after about a minute of being unfocused on Ubuntu 22.04 running in VirtualBox and with Wayland enabled. Previously this has happened every time, now it's just "sometimes". |
@mati865, there's a small chance that #2188 improves or fixes it, but if not, then please open an issue. I think we will need a log preferably from that PR, which has more diagnostics. I gave instructions for the tracy usage in this message #2162 (comment) |
Yeah, I've been watching #2188 already but planned to wait until it's merged. |
What kind of change does this PR introduce?
neovide_refresh_rate_idle
wakeup.window_separator_modifies_grid_and_sends_draw_command
had to be removed since supporting it would have been too complex requiring an event loop and everything.DrawCommandBatcher
has been greatly simplifiedEventAggregator
has been eliminated, and replaced by either raw channels or the winitevent_loop_proxy
for winit events.UICommand
s are now sent withsend_ui
EventAggregator
that allows almost any kind of communication any longer. These changes have been documented in the architecture comment inmain.rs
NOTE: The changes are rather big and a bit more testing would be good. So far I have only done basic testing on Wayland and Windows.
Did this PR introduce a breaking change?
A breaking change includes anything that breaks backwards compatibility either at compile or run time.