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: Optimization to resolve uris #5657

Merged
merged 2 commits into from
Sep 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions lib/util/manifest_parser_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,19 @@ shaka.util.ManifestParserUtils = class {
return baseUris;
}

if (baseUris.length == 1 && relativeUris.length == 1) {
const baseUri = new goog.Uri(baseUris[0]);
const relativeUri = new goog.Uri(relativeUris[0]);
return [baseUri.resolve(relativeUri).toString()];
}

const relativeAsGoog = relativeUris.map((uri) => new goog.Uri(uri));
// Resolve each URI relative to each base URI, creating an Array of Arrays.
// Then flatten the Arrays into a single Array.
return baseUris.map((uri) => new goog.Uri(uri))
.map((base) => relativeAsGoog.map((i) => base.resolve(i)))
.reduce(Functional.collapseArrays, [])
.map((uri) => uri.toString());
return baseUris.map((uri) => {
Copy link
Member

Choose a reason for hiding this comment

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

Would it help performance to rewrite this as a loop with no functional callbacks?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't see any difference using loops

const base = new goog.Uri(uri);
return relativeAsGoog.map((i) => base.resolve(i).toString());
}).reduce(Functional.collapseArrays, []);
}


Expand Down