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

perf: only update ui on change, wrap things in requestAnimationFrame #6155

Merged
merged 6 commits into from
Aug 29, 2019

Conversation

brandonocasey
Copy link
Contributor

@brandonocasey brandonocasey commented Aug 2, 2019

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

@brandonocasey brandonocasey force-pushed the perf/only-update-on-change branch from cfd8aeb to 57cf88b Compare August 2, 2019 19:34
// 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);
Copy link
Contributor Author

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.

Copy link
Member

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) {
Copy link
Contributor Author

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) {
Copy link
Contributor Author

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.

@brandonocasey brandonocasey force-pushed the perf/only-update-on-change branch from 0e940eb to aa431bb Compare August 2, 2019 19:52
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);
Copy link
Contributor Author

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) {
Copy link
Contributor Author

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) {
Copy link
Contributor Author

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) {
Copy link
Contributor Author

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) {
Copy link
Contributor Author

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) {
Copy link
Contributor Author

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;
Copy link
Contributor Author

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.

@brandonocasey brandonocasey force-pushed the perf/only-update-on-change branch from aa431bb to dd2e478 Compare August 2, 2019 19:59
@brandonocasey brandonocasey changed the title perf: only update on change perf: only update ui on change, wrap things in requestAnimationFrame Aug 2, 2019

this.formattedTime_ = formattedTime;
this.requestAnimationFrame(this.updateTextNode_);
if (oldNode) {
Copy link
Contributor Author

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(() => {
Copy link
Contributor Author

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.

@brandonocasey brandonocasey force-pushed the perf/only-update-on-change branch from 665687f to f3b8f03 Compare August 2, 2019 20:18
@brandonocasey brandonocasey force-pushed the perf/only-update-on-change branch from f3b8f03 to f07a341 Compare August 2, 2019 20:27
@brandonocasey brandonocasey force-pushed the perf/only-update-on-change branch from 9cd79bd to baf4c23 Compare August 2, 2019 21:34
Copy link
Member

@gkatsev gkatsev left a 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'});
Copy link
Member

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;
Copy link
Member

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?

Copy link
Contributor Author

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);
Copy link
Member

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?

Copy link
Contributor Author

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) {
Copy link
Member

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 😆.

@gkatsev gkatsev added the minor This PR can be added to a minor release. It should not be added to a patch release. label Aug 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
minor This PR can be added to a minor release. It should not be added to a patch release.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants