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

Large OptionList widgets are slow to load (since 0.86.0) #5498

Closed
TomJGooding opened this issue Jan 29, 2025 · 10 comments
Closed

Large OptionList widgets are slow to load (since 0.86.0) #5498

TomJGooding opened this issue Jan 29, 2025 · 10 comments

Comments

@TomJGooding
Copy link
Contributor

I've noticed that OptionList widgets with a large number of options take significantly longer to load since Textual 0.86.0.

The example below is an extreme scenario, but it demonstrates the difference in loading times.

Textual 0.85.2:
Loading OptionList with 10,000 options took 4.02s

Textual 0.86.0:
Loading OptionList with 10,000 options took 9.17s

Textual 1.0.0:
Loading OptionList with 10,000 options took 13.28s

from time import perf_counter

from textual import __version__
from textual.app import App, ComposeResult
from textual.widgets import OptionList

TOTAL_OPTIONS = 10_000


class ExampleApp(App):
    def compose(self) -> ComposeResult:
        content = [f"Option {i}/{TOTAL_OPTIONS}" for i in range(TOTAL_OPTIONS)]
        yield OptionList(*content)

    def on_ready(self) -> None:
        self.call_after_refresh(self.exit)


if __name__ == "__main__":
    start = perf_counter()

    app = ExampleApp()
    app.run()

    elapsed = perf_counter() - start
    print(f"**Textual {__version__}:**")
    print(f"Loading OptionList with {TOTAL_OPTIONS:,} options took {elapsed:.2f}s")
Copy link

We found the following entries in the FAQ which you may find helpful:

Feel free to close this issue if you found an answer in the FAQ. Otherwise, please give us a little time to review.

This is an automated reply, generated by FAQtory

@willmcgugan
Copy link
Collaborator

Previous iteration of the OptionList were lazy in calculating dimensions, which cause all sorts of flakiness. Now it does more work up-front. I suspect the timings look better in older versions because it is exiting before that lazy work is done.

It takes 6.45s on my machine currently with a feature branch that should speed up rendering.

The OptionList is also due for a re-write.

Closing this for now, will revisit after these changes are in.

Copy link

github-actions bot commented Feb 1, 2025

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

@TomJGooding
Copy link
Contributor Author

It takes 6.45s on my machine currently with a feature branch that should speed up rendering.

@willmcgugan Can I ask which feature branch so I can give it a go? That's quite a difference, though I suspect my old Thinkpad won’t keep up with your machine!

@willmcgugan
Copy link
Collaborator

It's in main now

@TomJGooding
Copy link
Contributor Author

TomJGooding commented Feb 7, 2025

Ah, that's what I feared. It takes ~16s on main on my machine, so actually 3s longer than before.

@willmcgugan willmcgugan reopened this Feb 11, 2025
@willmcgugan willmcgugan mentioned this issue Feb 11, 2025
5 tasks
@TomJGooding
Copy link
Contributor Author

TomJGooding commented Feb 11, 2025

Thanks for reopening this issue. That's quite an impressive difference on the new option list branch (currently down to 1.27s on my machine)!

@willmcgugan
Copy link
Collaborator

It's a wee bit faster now!

@TomJGooding
Copy link
Contributor Author

Closed by #5510.

Copy link

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants