Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataTable: Switching focus is slow when table contains lots of data #4737

Closed
ihabunek opened this issue Jul 14, 2024 · 4 comments · Fixed by #4748
Closed

DataTable: Switching focus is slow when table contains lots of data #4737

ihabunek opened this issue Jul 14, 2024 · 4 comments · Fixed by #4748
Labels
bug Something isn't working

Comments

@ihabunek
Copy link

I have a use case where I put data from a database into the data table and i noticed that if cells contain a lot of text, switching focus to and from the data table is very slow.

In the following example, when tab is pressed, it takes ~2 seconds to switch focus from the Input to the DataTable. Scrolling is reasonably fast once focused.

from textual.app import App
from textual.widgets import DataTable, Input

NUM_LINES = 100
NUM_COLS = 20
NUM_ROWS = 50

COLS = [f"col {n}" for n in range(NUM_COLS)]
# Each cell contains a bunch of text with line breaks
CELL = "\n".join("much data wow" for _ in range(NUM_LINES))
ROW = [CELL for _ in range(NUM_COLS)]
ROWS = [ROW for _ in range(NUM_ROWS)]


class ReproApp(App):
    CSS = "DataTable { height: 80%; }"

    def compose(self):
        yield Input("Pressing TAB to switch focus is slow!")
        dt = DataTable()
        dt.add_columns(*COLS)
        dt.add_rows(ROWS)
        yield dt


if __name__ == "__main__":
    app = ReproApp()
    app.run()

Textual Diagnostics

Versions

Name Value
Textual 0.72.0
Rich 13.7.1

Python

Name Value
Version 3.12.3
Implementation CPython
Compiler GCC 14.0.1 20240411 (Red Hat 14.0.1-0)
Executable /home/ihabunek/.virtualenvs/pgtui/bin/python

Operating System

Name Value
System Linux
Release 6.9.5-200.fc40.x86_64
Version #1 SMP PREEMPT_DYNAMIC Sun Jun 16 15:47:09 UTC 2024

Terminal

Name Value
Terminal Application Kitty
TERM xterm-kitty
COLORTERM truecolor
FORCE_COLOR Not set
NO_COLOR Not set

Rich Console options

Name Value
size width=182, height=48
legacy_windows False
min_width 1
max_width 182
is_terminal False
encoding utf-8
max_height 48
justify None
overflow None
no_wrap False
highlight None
markup None
height None
@Textualize Textualize deleted a comment from github-actions bot Jul 14, 2024
@darrenburns darrenburns added the bug Something isn't working label Jul 15, 2024
@darrenburns
Copy link
Member

Confirmed 👍

Copy link

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

@darrenburns
Copy link
Member

darrenburns commented Jul 16, 2024

@ihabunek Should be resolved in the next release (I'm guessing this week) for cases where cells contain text (str or rich.Text) content that spans multiple lines and only a portion of it is visible.

Load time of the DataTable should be much faster in those cases too, and focus/blur should be instant.

@ihabunek
Copy link
Author

@darrenburns I have tested on main and it seems much better. Thanks for your work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants