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: Throttle ProgressControl ui updates, add document.hidden check to time-displays #6150

Closed
wants to merge 11 commits into from

Conversation

brandonocasey
Copy link
Contributor

@brandonocasey brandonocasey commented Jul 31, 2019

So the activeElement mixin does the following:

  1. Manages starting and stoping an update function when:
    a. The player is/is not paused
    b. The component gains or loses Keyboard/mouse focus or player.userActive changes
    c. The tabs visibility (wether it is in the background or not) changes.
  2. Does not start anything until the player has started playback.

@brandonocasey brandonocasey changed the title perf: Add a mixin that throttles ui updates perf: Throttle ProgressControl ui updates, add document.hidden check to time-displays Jul 31, 2019
);

// Update the `PlayProgressBar` when we are in mouse focus
if (this.bar && (!this.parentComponent_ || this.parentComponent_.mouseFocus_)) {
Copy link
Contributor Author

@brandonocasey brandonocasey Aug 1, 2019

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';
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 need to do an update in progressControl rather then seekBar because progressControl is the component that is tabbed to and moused over.

@brandonocasey brandonocasey force-pushed the perf/active-update branch 4 times, most recently from 560a79d to 0450017 Compare August 1, 2019 16:36
1. Only update SeekBar's PlayProgressBar on mouseover
2. Only update SeekBar when seekbar is visible or in mouse/keyboard
   focus
import activeElement from '../../mixins/active-element.js';

// get the percent width of a time compared to the total end
const percentify = function(time, end) {
Copy link
Contributor Author

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.

Copy link
Contributor Author

@brandonocasey brandonocasey Aug 1, 2019

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

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.

Copy link
Contributor Author

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

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

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) {
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 not needed as this component is always visible for screen readers.

}

if (oldNode) {
this.contentEl_.replaceChild(this.textNode_, 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 about 10% faster than appendChild.

@brandonocasey
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant