After generating many many flame graphs, I’ve discovered a few reasons why nomad isn’t performing as well as it could be. Most of the optimisations to be had for the use cases I care about are to do with preventing unnecessary re-rendering of lines that have been rendered previously.
At the moment, nomad will re-draw N lines of the subterminal without caching the result. This means it will have to apply the formatting to every line for every tiny change, even when the cursor position updates!
I think one improvement could be to apply formats to lines when they change and store the formatted line in memory ready to be drawn later. This could require wrapping of formatted lines, which isn’t impossible but could be very tricky to get right.