Skip to content

Commit a35efd1

Browse files
Álvaro Velad Galvánjoeyparrish
authored andcommitted
fix(dash): Fix performance regression (#4064)
See: #4062 (comment)
1 parent 667962e commit a35efd1

File tree

6 files changed

+30
-27
lines changed

6 files changed

+30
-27
lines changed

lib/dash/dash_parser.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ goog.require('shaka.net.NetworkingEngine');
2121
goog.require('shaka.text.TextEngine');
2222
goog.require('shaka.util.Error');
2323
goog.require('shaka.util.Functional');
24-
goog.require('shaka.util.Iterables');
2524
goog.require('shaka.util.LanguageUtils');
2625
goog.require('shaka.util.ManifestParserUtils');
2726
goog.require('shaka.util.MimeUtils');
@@ -103,7 +102,7 @@ shaka.dash.DashParser = class {
103102

104103
/**
105104
* Period IDs seen in previous manifest.
106-
* @private {!Array.<number>}
105+
* @private {!Array.<string>}
107106
*/
108107
this.lastManifestUpdatePeriodIds_ = [];
109108

@@ -541,10 +540,9 @@ shaka.dash.DashParser = class {
541540
const periods = [];
542541
let prevEnd = 0;
543542
const periodNodes = XmlUtils.findChildren(mpd, 'Period');
544-
// This uses a for-loop rather than a for-of loop because this needs to look
545-
// ahead to the next element.
546-
const enumerate = (it) => shaka.util.Iterables.enumerate(it);
547-
for (const {i, item: elem, next} of enumerate(periodNodes)) {
543+
for (let i = 0; i < periodNodes.length; i++) {
544+
const elem = periodNodes[i];
545+
const next = periodNodes[i + 1];
548546
const start = /** @type {number} */ (
549547
XmlUtils.parseAttr(elem, 'start', XmlUtils.parseDuration, prevEnd));
550548
const periodId = elem.id;

lib/dash/mpd_utils.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ goog.require('shaka.net.NetworkingEngine');
1212
goog.require('shaka.util.AbortableOperation');
1313
goog.require('shaka.util.Error');
1414
goog.require('shaka.util.Functional');
15-
goog.require('shaka.util.Iterables');
1615
goog.require('shaka.util.ManifestParserUtils');
1716
goog.require('shaka.util.XmlUtils');
1817
goog.requireType('shaka.dash.DashParser');
@@ -142,8 +141,9 @@ shaka.dash.MpdUtils = class {
142141
const timeline = [];
143142
let lastEndTime = -unscaledPresentationTimeOffset;
144143

145-
const enumerate = (it) => shaka.util.Iterables.enumerate(it);
146-
for (const {item: timePoint, next} of enumerate(timePoints)) {
144+
for (let i = 0; i < timePoints.length; ++i) {
145+
const timePoint = timePoints[i];
146+
const next = timePoints[i + 1];
147147
let t = XmlUtils.parseAttr(timePoint, 't', XmlUtils.parseNonNegativeInt);
148148
const d =
149149
XmlUtils.parseAttr(timePoint, 'd', XmlUtils.parseNonNegativeInt);
@@ -225,8 +225,7 @@ shaka.dash.MpdUtils = class {
225225
timeline[timeline.length - 1].end = startTime / timescale;
226226
}
227227

228-
for (const _ of shaka.util.Iterables.range(repeat + 1)) {
229-
shaka.util.Functional.ignored(_);
228+
for (let j = 0; j <= repeat; ++j) {
230229
const endTime = startTime + d;
231230
const item = {
232231
start: startTime / timescale,

lib/dash/segment_template.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ goog.require('shaka.media.InitSegmentReference');
1414
goog.require('shaka.media.SegmentIndex');
1515
goog.require('shaka.media.SegmentReference');
1616
goog.require('shaka.util.Error');
17-
goog.require('shaka.util.Iterables');
1817
goog.require('shaka.util.ManifestParserUtils');
1918
goog.require('shaka.util.ObjectUtils');
2019
goog.requireType('shaka.dash.DashParser');
@@ -491,8 +490,9 @@ shaka.dash.SegmentTemplate = class {
491490

492491
/** @type {!Array.<!shaka.media.SegmentReference>} */
493492
const references = [];
494-
const enum_ = (it) => shaka.util.Iterables.enumerate(it);
495-
for (const {i, item: {start, unscaledStart, end}} of enum_(info.timeline)) {
493+
for (let i = 0; i < info.timeline.length; i++) {
494+
const {start, unscaledStart, end} = info.timeline[i];
495+
496496
// Note: i = k - 1, where k indicates the k'th segment listed in the MPD.
497497
// (See section 5.3.9.5.3 of the DASH spec.)
498498
const segmentReplacement = i + info.startNumber;

lib/util/string_utils.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,8 @@ shaka.util.StringUtils = class {
158158
static toUTF16(str, littleEndian) {
159159
const result = new ArrayBuffer(str.length * 2);
160160
const view = new DataView(result);
161-
const enumerate = (it) => shaka.util.Iterables.enumerate(it);
162-
for (const {i, item} of enumerate(str)) {
163-
const value = item.charCodeAt(0);
161+
for (let i = 0; i < str.length; ++i) {
162+
const value = str.charCodeAt(i);
164163
view.setUint16(/* position= */ i * 2, value, littleEndian);
165164
}
166165
return result;

lib/util/uint8array_utils.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,8 @@ shaka.util.Uint8ArrayUtils = class {
7474
// byte.
7575
const bytes = window.atob(str.replace(/-/g, '+').replace(/_/g, '/'));
7676
const result = new Uint8Array(bytes.length);
77-
const enumerate = (it) => shaka.util.Iterables.enumerate(it);
78-
for (const {i, item} of enumerate(bytes)) {
79-
result[i] = item.charCodeAt(0);
77+
for (let i = 0; i < bytes.length; ++i) {
78+
result[i] = bytes.charCodeAt(i);
8079
}
8180
return result;
8281
}

lib/util/xml_utils.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,13 @@ shaka.util.XmlUtils = class {
5656
* @return {!Array.<!Element>} The child XML elements.
5757
*/
5858
static findChildren(elem, name) {
59-
return Array.from(elem.childNodes).filter((child) => {
60-
return child instanceof Element && child.tagName == name;
61-
});
59+
const found = [];
60+
for (const child of elem.childNodes) {
61+
if (child instanceof Element && child.tagName == name) {
62+
found.push(child);
63+
}
64+
}
65+
return found;
6266
}
6367

6468

@@ -81,10 +85,14 @@ shaka.util.XmlUtils = class {
8185
* @return {!Array.<!Element>} The child XML elements.
8286
*/
8387
static findChildrenNS(elem, ns, name) {
84-
return Array.from(elem.childNodes).filter((child) => {
85-
return child instanceof Element && child.localName == name &&
86-
child.namespaceURI == ns;
87-
});
88+
const found = [];
89+
for (const child of elem.childNodes) {
90+
if (child instanceof Element && child.localName == name &&
91+
child.namespaceURI == ns) {
92+
found.push(child);
93+
}
94+
}
95+
return found;
8896
}
8997

9098

0 commit comments

Comments
 (0)