Skip to content

perf(ui): optimize animation thread to only run when needed - #6

Open
MedCy1 wants to merge 1 commit into
Ascendara:mainfrom
MedCy1:fix/animation-loop-optimization
Open

perf(ui): optimize animation thread to only run when needed#6
MedCy1 wants to merge 1 commit into
Ascendara:mainfrom
MedCy1:fix/animation-loop-optimization

Conversation

@MedCy1

@MedCy1 MedCy1 commented Jan 4, 2026

Copy link
Copy Markdown

Perf: Optimize animation loop to reduce CPU usage

What does this PR do?
This PR optimizes the background animation thread used for the progress bar. Instead of running a continuous 60 FPS loop even when idle, the thread now uses a threading.Event to sleep (block) until animation is explicitly required.

Why is this change necessary?
Previously, the _animation_loop was running constantly from the moment the application started, consuming unnecessary CPU cycles even when no installation was happening.
This change ensures the animation thread is dormant (0% CPU usage) until the "indeterminate" progress mode is active, and wakes up only when needed.

Key Changes:

  • Event-Driven Loop: Implemented threading.Event (self._animation_event) to control the animation thread.
  • CPU Optimization: The _animation_loop now waits for the event signal before calculating frames.
  • Thread Safety: Added try/except block in _update_animation_frame to prevent errors if the widget is destroyed during updates.
  • Cleanup: Updated the close() method to properly signal the thread to exit, ensuring no zombie threads remain after closing the app.

How to test:

  1. Run the installer (python app.py).
  2. Verify that the application is responsive while idle.
  3. Start an installation and verify that the "indeterminate" loading animation still works smoothly.
  4. Close the application while installing (or after) to ensure it closes cleanly without errors.

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 this pull request may close these issues.

1 participant