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

Optimize animation loop #21

Merged

Conversation

MarwanWalid2
Copy link
Contributor

Problem

The animation loop with a sleep time of 1e-3 seconds (1000Hz) paradoxically causes sluggish UI response when moving sliders. The tight loop consumes excessive CPU resources and doesn't allow enough time for processing UI events. Updating at 1000Hz provides no visual benefit but consumes resources

Solution

Increase the sleep time from 1e-3 seconds to 0.016 seconds (approximately 60Hz), which provides a better balance between animation smoothness and UI responsiveness.

Testing

I tested several values between 0.016-0.05 seconds and found that 0.016 provides the best responsiveness animation on my system (WSL) and another device. This change makes slider movements react in real-time while maintaining smooth visual updates.

For comparison:

  • 1e-3 (1000Hz): There is a delay between moving the slider and the actual movement
  • 0.016s (60Hz): Very smooth but higher CPU usage
  • 0.033s (30Hz): Good balance
  • 0.05s (20Hz): Also works well

@kkarol-bdai
Copy link
Collaborator

Great find!

@tcappellari-bdai tcappellari-bdai merged commit 63a05d1 into bdaiinstitute:main Mar 6, 2025
1 check passed
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.

3 participants