On 6 August 2014 22:48, Glyph Lefkowitz <glyph@twistedmatrix.com> wrote:

Optimizing this will almost certainly involve patching Twisted.  Which you should definitely do :).

The reason the entire screen is redrawn is that a general implementation of a widget, i.e. one that can be displayed anywhere on the terminal, you do just have to redraw the entire widget when certain things happen, like when the screen scrolls.  You can see this in other software by observing the fairly significant performance difference between a vertical split and a horizontal split in tmux.  Nothing to do with Twisted there, just a general limitation of terminals. 

The optimizations you could implement are one where inputting individual characters doesn't cause a full screen redraw, and avoiding a full screen redraw when scrolling if the edges of the widget touch the edges of the full terminal (setting up a scroll area for that case).

When manhole is used directly, then it is very responsive, and the performance doesn't degrade with increase of screen size. It holds only what user entered and writes the input line and command output directly to its transport, without bothering itself with processing of the whole screen. When I embed manhole into the widget like above, then the performance suffers. I think this is due to `TerminalBuffer` having to hold whole widget area (columns * rows) in memory, even if only a small portion of it is actually occupied by user input and command output. Rendering the whole buffer on each keystroke is slow. After experimenting a little bit, I think optimizations that you described mostly apply to `ManholeWidget.render` method, which shouldn't traverse the whole buffer on each keystroke. Currently I don't see how this involves patching widget implementation in Twisted. What is more important to me is that `TerminalBuffer` implementation is slightly incomplete. I think it misses color support, because I couldn't make it work with `ColoredManhole`.
 

-glyph

_______________________________________________
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python




--
Regards,
Maxim