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

fix(dash): Fix performance regression #4064

Merged
merged 1 commit into from Mar 25, 2022

Conversation

avelad
Copy link
Collaborator

@avelad avelad commented Mar 25, 2022

lib/dash/segment_template.js Outdated Show resolved Hide resolved
lib/dash/mpd_utils.js Outdated Show resolved Hide resolved
@philippe-elsass-deltatre
Copy link

philippe-elsass-deltatre commented Mar 25, 2022

@avelad can I suggest another improvement in xml_utils.js?

The following is MUCH faster (and causes less GC) than Array.from(elem.childNodes).filter:

  /**
   * Finds child XML elements.
   * @param {!Node} elem The parent XML element.
   * @param {string} name The child XML element's tag name.
   * @return {!Array.<!Element>} The child XML elements.
   */
  static findChildren(elem, name) {
    const found = [];
    for (const child of elem.childNodes) {
      if (child instanceof Element && child.tagName == name) {
        found.push(child);
      }
    }
    return found;
  }


  /**
   * Finds namespace-qualified child XML elements.
   * @param {!Node} elem The parent XML element.
   * @param {string} ns The child XML element's namespace URI.
   * @param {string} name The child XML element's local name.
   * @return {!Array.<!Element>} The child XML elements.
   */
  static findChildrenNS(elem, ns, name) {
    const found = [];
    for (const child of elem.childNodes) {
      if (child instanceof Element && child.localName == name &&
          child.namespaceURI == ns) {
        found.push(child);
      }
    }
    return found;
  }

@avelad
Copy link
Collaborator Author

avelad commented Mar 25, 2022

Done @philippe-elsass-deltatre

@philippe-elsass-deltatre

Still too slow though - I'm investigating.

@avelad
Copy link
Collaborator Author

avelad commented Mar 25, 2022

@philippe-elsass-deltatre do you have any update?

@philippe-elsass-deltatre

I'm profiling Shaka 2.5 VS 3 (debug versions), and Shaka 2.5 is still literally twice as fast. Not sure why.

@@ -225,8 +225,7 @@ shaka.dash.MpdUtils = class {
timeline[timeline.length - 1].end = startTime / timescale;
}

for (const _ of shaka.util.Iterables.range(repeat + 1)) {
shaka.util.Functional.ignored(_);
for (let j = 0; j <= repeat; ++j) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For historical context, we used to have frequent issues with mistakes in code like this. It is easy to mix up i and j for example, and easy to overlook in code review. So Iterables was a way to avoid the need for those.

Clearly the performance penalty is too great, though. We should figure out what other things transpile into poorly-performing ES5 and eliminate them. We could even write a test that would check the binary for poorly-performing polyfills, to catch regressions.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From Monday I will continue working on other improvements, but I will create other PRs.

@joeyparrish joeyparrish merged commit 298b604 into shaka-project:main Mar 25, 2022
@avelad
Copy link
Collaborator Author

avelad commented Mar 25, 2022

@joeyparrish can you cherry-pick it to 3.3? Thanks!

@avelad avelad deleted the fix-dash-performance branch March 28, 2022 05:46
joeyparrish pushed a commit that referenced this pull request Apr 21, 2022
joeyparrish pushed a commit that referenced this pull request Apr 21, 2022
joeyparrish pushed a commit that referenced this pull request Apr 21, 2022
@avelad avelad added this to the v4.0 milestone May 4, 2022
@github-actions github-actions bot added the status: archived Archived and locked; will not be updated label Jul 25, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: archived Archived and locked; will not be updated
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants