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

Refactor main TUI loop to reduce latency in handling messages #187

Merged
merged 1 commit into from
Apr 29, 2024

Conversation

LucasPickering
Copy link
Owner

Description

Describe the change. If there is an associated issue, please include the issue link (e.g. "Closes #xxx"). For UI changes, please also include screenshots.

Previously, the main loop was rate-limited by the terminal input poll() call. This means when no user input was present, it would block for 250ms before handling any async messages. This could cause some annoying UI delays for changes triggered by background IO (e.g. HTTP responses could take up to 250ms extra to appear). By breaking the input loop into a separate task, and having the main loop block directly on the message queue, we ensure that every message is handled immediately and we update the UI immediately.

I measured CPU usage on this, and it's the same as master. Locally I see ~5% usage whlie running in debug and ~0.7% while running with --release. This makes sense because the CPU is doing all the same work, just rearranged slightly.

This has the added benefit that it accidentally fixed #136, which is great because I really didn't want to debug that anymore.

Known Risks

What issues could potentially go wrong with this change? Is it a breaking change? What have you done to mitigate any potential risks?

Both high and low. This is the main loop so obviously if something is wrong it would be very bad, but that means it's very easy to check if it's working. Basic TUI functionality (accepting input, sending requests) works so I'm confident the loop is doing it's thing. I never fully understood the 100% CPU bug so there's a risk it still exists in some form, but I wasn't able to reproduce it anymore.

QA

How did you test this?

Run some requests in the TUI, measure CPU usage. To test the fixed bug, I ran cargo run from inside a zellij session, then quit zellij as a whole (with ctrl-q) and watched the Slumber process die. The exact same steps previously would leave the Slumber process behind and it would spike to 100% CPU usage.

Checklist

  • Did you update CHANGELOG.md?
    • Only user-facing changes belong in the changelog. Internal changes such as refactors should only be included if they'll impact users, e.g. via performance improvement.
  • Did you remove all TODOs?
    • If there are unresolved issues, please open a follow-on issue and link to it in a comment so future work can be tracked

@LucasPickering LucasPickering force-pushed the loop-refactor branch 2 times, most recently from 4f05aef to 28bfc88 Compare April 29, 2024 11:35
Previously, the main loop was rate-limited by the terminal input poll() call. This means when no user input was present, it would block for 250ms before handling any async messages. This could cause some annoying UI delays for changes triggered by background IO (e.g. HTTP responses could take up to 250ms *extra* to appear). By breaking the input loop into a separate task, and having the main loop block directly on the message queue, we ensure that every message is handled immediately and we update the UI immediately.

I measured CPU usage on this, and it's the same as master. Locally I see ~5% usage whlie running in debug and ~0.7% while running with --release. This makes sense because the CPU is doing all the same work, just rearranged slightly.

This has the added benefit that it accidentally fixed #136, which is great because I really didn't want to debug that anymore.
@LucasPickering LucasPickering enabled auto-merge (rebase) April 29, 2024 11:40
@LucasPickering LucasPickering merged commit 7760728 into master Apr 29, 2024
10 checks passed
@LucasPickering LucasPickering deleted the loop-refactor branch April 29, 2024 11:40
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

Successfully merging this pull request may close these issues.

slumber process hangs at 100% CPU if parent process is killed
1 participant