-
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: only update ui on change, wrap things in requestAnimationFrame #6155
Conversation
676a919
to
cfd8aeb
Compare
cfd8aeb
to
57cf88b
Compare
// The default skin has a gap on either side of the `SeekBar`. This means | ||
// that it's possible to trigger this behavior outside the boundaries of | ||
// the `SeekBar`. This ensures we stay within it at all times. | ||
seekBarPoint = clamp(0, 1, seekBarPoint); |
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.
Use the new clamp function to keep this between 1 and 0.
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.
@brandonocasey I was just looking at this PR, and I think you have the parameters to clamp
in the wrong order here, based on your comment?? This merged change seems to still be in the latest code - I'm wondering if it's a bug?
const playProgressBar = seekBar.getChild('playProgressBar'); | ||
const mouseTimeDisplay = seekBar.getChild('mouseTimeDisplay'); | ||
|
||
if (!playProgressBar && !mouseTimeDisplay) { |
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.
Don't do anything if we don't have either child.
mouseTimeDisplay.update(seekBarRect, seekBarPoint); | ||
} | ||
|
||
if (playProgressBar) { |
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.
Update the playProgressBar
here as well because we only show it on mousemove
and because getting the seekBarRect is a very performance impacting thing.
0e940eb
to
aa431bb
Compare
this.on(this.player_, 'timeupdate', this.update); | ||
this.on(this.player_, 'ended', this.handleEnded); | ||
this.on(this.player_, 'durationchange', this.update); | ||
this.on(this.player_, ['ended', 'durationchange', 'timeupdate'], this.update); |
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.
ended
is now handled in update
itself.
} | ||
} | ||
|
||
enableInterval_() { | ||
this.clearInterval(this.updateInterval); | ||
if (this.updateInterval) { |
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.
clearInterval takes time, only do it if we have to.
} | ||
|
||
disableInterval_(e) { | ||
if (this.player_.liveTracker && this.player_.liveTracker.isLive() && e.type !== 'ended') { | ||
return; | ||
} | ||
|
||
if (!this.updateInterval) { |
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.
clearInterval takes time, only do it if we have to.
* | ||
* @private | ||
*/ | ||
update_(currentTime, 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.
All of this logic was moved to the update
function.
); | ||
|
||
// Update the `PlayProgressBar`. | ||
if (this.bar) { |
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 update this in progress-control
now, next to mouseTimeDisplay
@@ -169,15 +133,41 @@ 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 never did anything since seek bar is always visible as far as the dom is concerned due to screen readers.
@@ -231,7 +208,7 @@ class SeekBar extends Slider { | |||
percent = currentTime / this.player_.duration(); | |||
} | |||
|
|||
return percent >= 1 ? 1 : (percent || 0); | |||
return 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.
This is clamped in slider now.
aa431bb
to
dd2e478
Compare
|
||
this.formattedTime_ = formattedTime; | ||
this.requestAnimationFrame(this.updateTextNode_); | ||
if (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 10% faster then appendChild.
|
||
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.
wrap in a requestAnimationFrame and only update when changed.
665687f
to
f3b8f03
Compare
f3b8f03
to
f07a341
Compare
9cd79bd
to
baf4c23
Compare
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.
First review for load progress bar. Didn't get a chance to look at the others yet.
className: 'vjs-load-progress', | ||
innerHTML: `<span class="vjs-control-text"><span>${this.localize('Loaded')}</span>: <span class="vjs-control-text-loaded-percentage">0%</span></span>` | ||
const el = super.createEl('div', {className: 'vjs-load-progress'}); | ||
const wrapper = super.createEl('span', {className: 'vjs-control-text'}); |
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.
I think we only want to call super.createEl for the main div, the children should be Dom.createEl.
const start = buffered.start(i); | ||
const end = buffered.end(i); | ||
let part = children[i]; | ||
part.start_ = start; |
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 should avoid setting properties on DOM elements. Maybe data-attribute will be fine?
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.
that will probably work.
|
||
// update the width of the progress bar | ||
this.el_.style.width = percentify(bufferedEnd, duration); |
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.
I wonder if there's a big difference between using the rounded vs non-rounded value here. Probably not noticeable?
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.
I think css only ever uses two decimal places, it's possible I am wrong though.
@@ -100,12 +100,12 @@ class LoadProgressBar extends Component { | |||
} | |||
|
|||
// only update if changed | |||
if (part.start_ === start && part.end_ === end) { | |||
if (part.dataset.start === start && part.dataset.end === 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.
suprisingly, IE11 keeps having more support for features than I'd expect 😆.
Description
Only update ui components when something has actually changed and wrap ui changes in requestAnimationFrame. This nets us most of the benefit from #6150