This is an alternative PR to #401, taking things a step further.
term_print() is called whenever the client application “prints” something to the grid. It is called for both ASCII and UTF-8 characters, and needs to handle sixels, insert mode and ASCII vs. graphical charsets.
Since it’s on the hot path, this becomes unnecessarily slow.
This patch adds a “fast” version of term_print(), tailored for the common case: ASCII characters in non-insert mode, without any sixels and non-graphical charsets.
A new function, term_update_ascii_printer(), has been added, and must be called whenever:
The currently selected charset index changes
The currently selected charset changes (from ASCII to graphical, or vice verse)
Sixels are added to the grid
Sixels are removed from the grid
Insert mode is enabled/disabled
Switching to/from alt screen (since that may change how many sixels we have)
That's a ~10% performance boost, which isn't too bad considering this code path is already fairly optimized. As expected, no difference in the scrolling benchmarks.
The downside is all the calls to term_update_ascii_printer() spread out over the code base. Not really fond of that.