Skip to content

Updating a Datatable multiple times a second causes hugh CPU spikes #6457

@hellow554

Description

@hellow554

The bug

I use a datatable to display data. I have roughly 150 rows, each consiting of 5 fields.
I receive real time items every 100ms and update the datatable according. This is my update code:

def _create_or_update_row(self, key: str, data: ContentType) -> None:
    if key in self.table.rows:
        for field in fields(data):
            self.table.update_cell(
                key,
                field.name,
                _dump_field(field.name, getattr(data, field.name)),
                update_width=True,
            )
    else:
        self.table.add_row(
            key,
            *(_dump_field(field.name, getattr(data, field.name)) for field in fields(data)),
            key=key,
        )

This is triggered by a message:

@on(DataChanged)
def data_changed(self, message: DataChanged) -> None:
    self._create_or_update_row(message.key, message.ct)

This results in a huge CPU spike, roughly to 60% and higher:

Image

This is due to a lot of ioctl calls, if I see that correctly:

Image

and this happens a lot!!!

I can try to set up a simple project that reproduces the problem, but maybe you can tell me, what I'm doing wrong here.
Maybe this could be fixed by cachine the TIOCGWINSZ result and wait for SIGWINCH or similar?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions