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

ProgressBar: decrease CPU consumption by adjusting Bar.auto_refresh when styles.display is None #4835

Closed
xavierog opened this issue Aug 3, 2024 · 3 comments · Fixed by #4847

Comments

@xavierog
Copy link
Contributor

xavierog commented Aug 3, 2024

Overall, ProgressBar is not a CPU-greedy widget. It does bring a small yet noticeable increase in CPU consumption when left in "indeterminate" mode since this mode involves a sliding animation. As far as I can tell, this is both normal and acceptable.

However, I noticed this CPU consumption does not decrease when the progress bar is hidden (e.g. self.progress_bar.styles.display = 'none'). This could be improved by adjusting Bar.auto_refresh whenever necessary.

Currently, Bar.auto_refresh only reacts to changes of the percentage attribute:

def watch_percentage(self, percentage: float | None) -> None:
"""Manage the timer that enables the indeterminate bar animation."""
if percentage is not None:
self.auto_refresh = None
else:
self.auto_refresh = 1 / 15

Copy link

github-actions bot commented Aug 3, 2024

We found the following entry 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

Good point. It probably makes sense for the auto_refresh feature to check if the widget is actually visible before refreshing. Should be a trivial change.

Copy link

github-actions bot commented Aug 6, 2024

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

@xavierog xavierog changed the title Displaybar: decrease CPU consumption by adjusting Bar.auto_refresh when styles.display is None ProgressBar: decrease CPU consumption by adjusting Bar.auto_refresh when styles.display is None Aug 11, 2024
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

Successfully merging a pull request may close this issue.

2 participants