Optimize auto-advance logic in TimeRange
#70
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
rAF
callback, avoid synchronous re-layouts as much as possible. We now cache the bar and thumb widths more aggressively.rAF
callback, check if the change incurrentTime
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.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 everytimeupdate
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.