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

Live: only draw when UI needs update #10

Open
nelson137 opened this issue Oct 25, 2023 · 1 comment
Open

Live: only draw when UI needs update #10

nelson137 opened this issue Oct 25, 2023 · 1 comment
Labels
C-live Command: live D-medium Difficulty: medium E-feature Enhancement: new feature or request

Comments

@nelson137
Copy link
Owner

nelson137 commented Oct 25, 2023

Ratatui does double buffering to efficiently update the terminal by only writing out what changed between draw calls. However, the UI is always redrawn every tick, and Ratatui is an immediate-mode framework meaning that the entire UI must be rebuilt in memory. Most of the time there will be no or few changes, meaning most of the just-created widgets will not be used.

Taking inspiration from the paradigms used in tui-realm, only call Terminal::draw if an event causes a state update. The main loop and event processing may need refactoring to make this easy.

Additionally, gather some metrics to see how this affects performance:

  • Measure how long it takes to render per tick
  • Monitor CPU usage before/after the change
@nelson137 nelson137 added E-feature Enhancement: new feature or request C-live Command: live D-medium Difficulty: medium labels Oct 25, 2023
@joshka
Copy link

joshka commented Jan 26, 2024

You might be interested to see what we have cooking in the 0.26.0 release...

Specifically we now support rendering references to all our widgets (except barchart), and the tehnique may work for your app too. See ratatui/ratatui#833 for some info and ratatui/ratatui#836 for a demo. This also can work for mutable refs, but care should be taken to not do destructive things tot the state that would prevent things rendering well. https://github.com/ratatui-org/ratatui/pull/865/files

A new alpha should be out sometime today / tomorrow if you want to take a look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-live Command: live D-medium Difficulty: medium E-feature Enhancement: new feature or request
Projects
None yet
Development

No branches or pull requests

2 participants