perf(vt100) increase render performance for tui_term
codepath
#9123
+64
−20
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
The crate
tui_term
renders thevt100::Screen
by fetching each cell and then filling theratatui::buffer:Cell
with the vt100 cell's contents.This leads to the following functions being called once for each cell on the users terminal:
Cell::contents
which unnecessarily allocates on every call even though there's a fixed limit to the size of thestr
that could be returned. This PR changes this method to return a&str
that is constructed from the content bytes. The new helper functionappend_char
is basicallyString::push
Grid::visible_row
which iterates through the scrollback rows and screen rows. This PR changes this to instead index directly into the rowsTesting Instructions
Tested by profiling this basic script that render a tui_term 1000 times.
The two functions that this targets:
fill_buf_cell
codepathBefore
After
Aftervisible_cell
codepathBefore