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 auto-advance logic in TimeRange #70

Merged
merged 9 commits into from
Aug 29, 2024

Conversation

MattiasBuelens
Copy link
Collaborator

@MattiasBuelens MattiasBuelens commented Aug 28, 2024

Currently, the auto-advance logic in <theoplayer-time-range> runs very frequently (every animation frame), even in cases where it's not really needed. This can cause performance issues on lower end devices and smart TVs.

This PR improves this in a number of ways:

  • Inside our rAF callback, avoid synchronous re-layouts as much as possible. We now cache the bar and thumb widths more aggressively.
  • Inside our rAF callback, check if the change in currentTime is large enough to be noticeable on the screen. That is: if the thumb would move by at least 1 pixel. If the change is less than that, we don't advance at all.
  • If the change in currentTime needed to move the thumb by 1 pixel is larger than 250ms, then we don't run our auto-advance logic at all. In this case, it's sufficient to update on every timeupdate event, which is guaranteed to fire at least once every 250ms anyway. This improvement is especially noticeable for longer videos, where the thumb might not need to move for several seconds.

@MattiasBuelens MattiasBuelens added the enhancement New feature or request label Aug 28, 2024
@MattiasBuelens MattiasBuelens merged commit c59f859 into develop Aug 29, 2024
1 check passed
@MattiasBuelens MattiasBuelens deleted the optimize-time-range branch August 29, 2024 08:37
@theoplayer-bot theoplayer-bot bot mentioned this pull request Aug 29, 2024
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant