TerminalSession.resize() allocates a new grid using a for loop to construct (Style(), " ") tuples.
This is necessary for mutable objects but slow. Resizing a grid to 1000x1000 must allocate 2M objects or more. Because the tuple, the string and the Style are immutable, it would be better to allocate with
grid = [
[(Style(), " ")] * width
for row in range(height)
]
TerminalSession.resize()allocates a new grid using a for loop to construct(Style(), " ")tuples.This is necessary for mutable objects but slow. Resizing a grid to 1000x1000 must allocate 2M objects or more. Because the tuple, the string and the Style are immutable, it would be better to allocate with