textual icon indicating copy to clipboard operation
textual copied to clipboard

Investigate reducing TextArea updates

Open willmcgugan opened this issue 1 year ago • 4 comments

The TextArea tends to refresh the entire widget on update. We should investigate the possibility of either programatically figuring out changed regions, or doing some kind of automatic comparison with the previous frame.

willmcgugan avatar Jan 31 '24 17:01 willmcgugan

I think this would be incredibly difficult to implement within the TextArea itself unless we opted for a diffing approach, and if we're doing that, it'd probably be better to do it at the Textual level somehow. There are just so many things that can result in lines changing outwith the line that is currently being edited (syntax highlighting, wrapping, an edit can result in scrollbars appearing which can change wrapping, some edits can influence lines below them, and so on...).

darrenburns avatar Feb 01 '24 10:02 darrenburns

Could you let me know your thoughts @willmcgugan?

darrenburns avatar Feb 15 '24 18:02 darrenburns

Ideally the widget can calculate which areas change, but as you said the TextArea makes that impractical.

I think we could do a diffing approach at the Textual level. When we render the widget we can store the rendered strips somewhere, then when we render a subsequent frame we could compare them line by line and only refresh lines which have changed.

This wouldn't be very precise. If we have a flashing cursor it would update a line rather than a single cell, but it would be better that updating the entire widget.

I think this should be an opt-in thing for line API widgets. May delta_updates=True or something.

willmcgugan avatar Feb 19 '24 13:02 willmcgugan

@davep @rodrigogiraoserrao Please consider tackling this. Let me know if you want to discuss your approach beforehand.

willmcgugan avatar Mar 21 '24 12:03 willmcgugan