Skip to content

Improvements to TUI rendering efficiency - #332

Merged
maximmaxim345 merged 4 commits into
Sendspin:mainfrom
YoshiWalsh:tui-rendering-performance
Dec 1, 2026
Merged

maximmaxim345 merged 4 commits into
Sendspin:mainfrom
YoshiWalsh:tui-rendering-performance

Conversation

@YoshiWalsh

@YoshiWalsh YoshiWalsh commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

What does this implement/fix?

On my Ryzen 1800X I have a lot of issues with stuttering when the TUI is at large-ish resolutions. I profiled the TUI and realised that the rich library is quite inefficient. An ideal solution would be to move to using curses instead, but that would be a lot of work. Instead, I have focussed on reducing the number of expensive calls present in the hot-path.

These changes involve caching the widths and heights of various TUI elements, only invalidating these caches when the terminal is resized. This saves making many calls to various heavy "measure" functions every frame.

These changes reduce the time to output a "frame" of text by ~20% on average, according to profiling.sampling. Unfortunately this is still not enough to eliminate stuttering issues on my PC, but it's a step in the right direction.

Related issue (if applicable):

Types of changes

  • Bugfix (non-breaking change which fixes an issue): bugfix
  • New feature (non-breaking change which adds functionality): new-feature
  • Enhancement to an existing feature: enhancement
  • Breaking change (changes CLI options, settings, hooks or the protocol in a way that is not backwards compatible): breaking-change
  • Refactor (no behavior change): refactor
  • Documentation only: documentation
  • Maintenance / chore: maintenance
  • CI / workflow change: ci
  • Dependencies bump: dependencies

On my Ryzen 1800X I have a lot of issues with stuttering when the TUI is at large-ish resolutions. I profiled the TUI and realised that the `rich` library is quite inefficient. An ideal solution would be to move to using `curses` instead, but that would be a lot of work. Instead, I have focussed on reducing the number of expensive calls present in the hot-path.

These changes involve caching the widths and heights of various TUI elements, only invalidating these caches when the terminal is resized. This saves making many calls to various heavy "measure" functions every frame.

These changes reduce the time to output a "frame" of text by over 50% on average, according to profiling.sampling. Unfortunately this is still not enough to eliminate stuttering issues on my PC, but it's a step in the right direction.
@YoshiWalsh

YoshiWalsh commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor Author

Flamechart before:

image

Flamechart after:

image

You can see that the "flame" for SendspinUI._measure_layout_height call no longer appears, same for the Table.__rich_measure__ flame.

@github-actions github-actions Bot added the refactor Changes code without changing behavior label Dec 1, 2026
The visualizer lost its bottom row or left a blank one after a title or
status message wrapped differently, until the next resize.

@maximmaxim345 maximmaxim345 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @YoshiWalsh!

Pushed two small fixes and a test on top. The visualizer now keeps the right height when a title or status message wraps onto another line, and cached panel widths are now measured again after a resize.
Tested side by side with main in a group on a Music Assistant dev server.

@github-actions github-actions Bot added enhancement Improves an existing feature and removed refactor Changes code without changing behavior labels Dec 1, 2026
@maximmaxim345
maximmaxim345 merged commit d0410ac into Sendspin:main Dec 1, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Improves an existing feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants