Commit graph

6 commits

Author SHA1 Message Date
Kovid Goyal
62124e1d8e
Ignore the paused rendering snapshot when rendering is not paused
The snapshot of the screen taken for a synchronized update is kept after
the update ends, so its cells prevented the style table from being
emptied on hard resets and clearing of the scrollback, and kept their
styles alive through garbage collection. It is unused when rendering is
not paused and is overwritten entirely when rendering is next paused, so
only consider it while rendering is paused.

Also detect use of the formatting of stale line copies when comparing
lines and in test_shape() and test_render_line().
2026-11-19 19:57:37 +05:30
Kovid Goyal
a0aea76c7a
Only empty the style table on hard resets and clearing the scrollback
Emptying it whenever the whole screen was erased meant that full screen
programs, which erase the screen on every redraw, had all their styles
interned again and the style texture uploaded again every frame. Also do
not empty tables with few styles, as they are not worth it. Empty it when
the scrollback is cleared by the clear_terminal action as well.

Improves the truecolor text and half blocks benchmarks by 50% and 33%.
2026-11-19 19:57:37 +05:30
Kovid Goyal
3b7a0a6bb0
Double the maximum number of cell styles
Remove the temp_flag bit from CPUCell, which was used only to mark the
cells whose text is extracted for a selection, and use a temporary bitmap
for that instead. The freed bit is used for the style index, doubling
the maximum number of styles to 262144.
2026-11-19 19:57:37 +05:30
Kovid Goyal
daa2624fb1
Detect use of the formatting of stale line copies
Copies of lines made with LineBuf.create_line_copy() are not remapped
when the style table of their screen is garbage collected, so their
style indices become invalid. Record the generation of the style table
in copies and raise ValueError when the formatting of a copy made
before a collection is used. Copying a whole line into a copy makes
its formatting valid again.
2026-11-19 19:57:37 +05:30
Kovid Goyal
926343d576
Empty the style table when no cell uses a style
On a hard reset or when erasing the whole display, if the scrollback is
empty and no cell on any screen buffer has a style, empty the style
table, freeing the memory used by styles from, for example, a burst of
output with many colors. Checking is cheap as only the screen buffers
need to be scanned.
2026-11-19 19:57:36 +05:30
Kovid Goyal
11a121ae5f
Intern cell styles and store only CPUCells in the scrollback
The formatting of cells (colors and SGR attributes) is now interned per
screen in a StyleTable and cells store a 17 bit index into it in the
previously unused bits of CPUCell. Render data (sprite and mark) is kept
in a separate RenderCell array for screen lines and in a small render
cache for history lines being displayed, so the scrollback stores only
CPUCells, 12 bytes per cell instead of 32. GPUCell is now only the upload
format, built from the CPUCell, its style and its RenderCell.

When the table fills up, it is compacted at the start of drawing text,
reducing the color precision of cells in the scrollback if needed, cells
on screen always keep their exact styles. The map from styles to indices
is a verstable set of indices with a small cache of recent styles in
front of it.

benchmark.py throughput: ascii +48%, unicode +29%, csi +10%, truecolor
text -22%, truecolor half blocks -9%.
2026-11-19 19:57:36 +05:30