Skip to content

resize() allocates new objects for each cell #9

Description

@lordmauve

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)
]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions