-
-
Notifications
You must be signed in to change notification settings - Fork 651
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(pty): use async io to avoid polling #523
Conversation
I made a measurement of
However, during these measurements, I've noticed a problem. This benchmark measures the time it takes for This results in both user visible lagging, and ballooning memory usage by all the This problem is exacerbated by this PR, as it makes streaming faster. Perhaps the
The proper solution would be a having back pressure between |
b307b63
to
f8784f5
Compare
Hey @kxt - this looks great at a very brief first glance. I want to give this a more thorough dive (both to test it and understand the difference in behaviour and the new code changes). Unfortunately, I've been having a bit of a day, so I won't have a chance to get to it today. I'm setting some time aside for it tomorrow though. Thank you for your patience :) |
Unfortunately it's a bit involved code, sorry about that. I might be able to clean up it a little before you dive into it tomorrow. |
Nah, it's fine :) Only thing that might be good (for me and future readers) is to add comments around more advanced features to explain why you used them (eg. the async trait and unsafe block) |
I've updated the patch, hopefully
The unsafe part is however a big deal. Closing the |
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.
Hey! Thanks for the updates. This really looks great. Certainly much better in every way than what we had before. I left a couple of minor nitpicks, but I don't have much to say about the code otherwise.
The behaviour change is a little problematic though, as you pointed out in the linked issue. I'm going to comment on it here because I think it'll be easier. (orig issue: #525)
An alternative explanation (kudos to @aeinstein): running nearly at the speed of light, cat is experiencing time dilation compared to a stationary observer.
(I laughed quite a bit at this)
I made a proof-of-concept using a bounded to_screen queue, and I ran into a deadlock: [...] which is already filled by pty thread, so this send is blocking.
Kudos on all the threading. I agree that this is a problematic part of our architecture. IMO a better solution would be to decouple the plugin rendering from the plugin state updating. Maybe even to have them be long-lived and operating in the background, sending their visual state to the screen thread to be rendered as needed. But I guess @TheLostLambda might have more to say about this.
There's also ongoing work being done on the rendering itself to cut down its cost significantly, which I think will be a big help here.
Either way, I hope these changes don't need to block this PR. Do you think there's some way to workaround the backpressure issue? Even adding an artificial amount of sleep that won't be 100% on every machine but will be good enough? Or some other solution?
Because visually to users, this seems like a performance degradation for large amounts of output - and I'm hesitant to worsen the UX here.
This patch fixes zellij-org#509 by using async read instead of polling a non-blocking fd. This reduces CPU usage when the ptys are idle.
This is a YMMV kinda problem. The code currently has a 10ms sleep, that's the same as the old code. However, due to the higher throughput, there might be some systems that were somewhat laggy with the old code because it kept the I have a few more ideas for implementing back pressure that I want to try before we upend the entire threading architecture, I'll keep #525 posted. |
I did not know that #525 is blocking this PR, and it's not clear to me why it does.
|
My apologies for the confusion then. I took another look at this and while the performance is a little janky here when catting large files, it's MUCH faster. I think the jankyness is this exposing the soon-to-be-fixed flaws of our render function itself. |
Also, thanks for this @kxt! And thanks for your patience with the merges from main, I know it can be frustrating. |
This patch fixes #509 by using async read instead of polling a
non-blocking fd. This reduces CPU usage when the ptys are idle.