-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
perf: Throttle ProgressControl ui updates, add document.hidden check to time-displays #6150
Conversation
198dc31
to
84657d1
Compare
); | ||
|
||
// Update the `PlayProgressBar` when we are in mouse focus | ||
if (this.bar && (!this.parentComponent_ || this.parentComponent_.mouseFocus_)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is only shown when the mouse is over progressControl
, so only update then.
@@ -4,6 +4,8 @@ | |||
import Component from '../../component.js'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to do an update in progressControl
rather then seekBar
because progressControl
is the component that is tabbed to and moused over.
560a79d
to
0450017
Compare
1. Only update SeekBar's PlayProgressBar on mouseover 2. Only update SeekBar when seekbar is visible or in mouse/keyboard focus
0450017
to
1912049
Compare
import activeElement from '../../mixins/active-element.js'; | ||
|
||
// get the percent width of a time compared to the total end | ||
const percentify = function(time, end) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There isn't a good reason for this to define this every time the update function is run.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also css only takes into account the first two decimal places so we should just always round.
|
||
if (rounded) { | ||
percent = percent.toFixed(2); | ||
this.requestAnimationFrame(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without requestAnimationFrame
this ran on the main thread, and it took a good chunk of time too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hiding whitespace changes makes this a lot easier to diff.
const controlTextPercentage = this.$('.vjs-control-text-loaded-percentage'); | ||
const percent = percentify(bufferedEnd, duration); | ||
|
||
if (this.el_.style.width !== percent) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only update the style if it changed
part = this.el_.appendChild(Dom.createEl()); | ||
children[i] = part; | ||
} | ||
if (part.style.left !== leftPercent) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only update when changed.
@@ -169,12 +109,6 @@ class SeekBar extends Slider { | |||
* The current percent at a number from 0-1 | |||
*/ | |||
update(event) { | |||
// if the offsetParent is null, then this element is hidden, in which case | |||
// we don't need to update it. | |||
if (this.el().offsetParent === null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not needed as this component is always visible for screen readers.
} | ||
|
||
if (oldNode) { | ||
this.contentEl_.replaceChild(this.textNode_, oldNode); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
replaceChild is about 10% faster than appendChild.
This just became too complicated, I broke out most of the logic into #6155. I will close this one and open another with the changes here. |
So the activeElement mixin does the following:
a. The player is/is not paused
b. The component gains or loses Keyboard/mouse focus or
player.userActive
changesc. The tabs visibility (wether it is in the background or not) changes.