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

url: refactor to use more primordials #45966

Merged
merged 11 commits into from Jan 22, 2023
Merged

Conversation

aduh95
Copy link
Contributor

@aduh95 aduh95 commented Dec 24, 2022

No description provided.

@aduh95 aduh95 added whatwg-url Issues and PRs related to the WHATWG URL implementation. needs-benchmark-ci PR that need a benchmark CI run. labels Dec 24, 2022
@nodejs-github-bot nodejs-github-bot added the needs-ci PRs that need a full CI run. label Dec 24, 2022
Copy link
Member

@anonrig anonrig left a comment

Choose a reason for hiding this comment

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

This pull request includes changes more than just refactoring primordial, and might confuse reviewers. I recommend either changing the title of this pull request or introducing changes other than primordials to a different pull request.

Can you also run a benchmark?

if (!isWindows) filepath = StringPrototypeReplaceAll(filepath, '\\', '%5C');
filepath = StringPrototypeReplaceAll(filepath, '\n', '%0A');
filepath = StringPrototypeReplaceAll(filepath, '\r', '%0D');
filepath = StringPrototypeReplaceAll(filepath, '\t', '%09');
Copy link
Member

Choose a reason for hiding this comment

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

According to micro-benchmarks, ReplaceAll is slower than Replace. I prefer using the existing implementation. Referencing: https://github.com/RafaelGSS/nodejs-bench-operations/blob/main/RESULTS-v19.md

Copy link
Contributor Author

@aduh95 aduh95 Dec 25, 2022

Choose a reason for hiding this comment

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

The existing implementation relies on user-mutable RegExp.prototype[Symbol.replace]. According to my own research, replaceAll on a string was faster than building a robust regex. (Actually in this case we're reusing the same regex, so it should not really matter, let's go with the regex approach)

lib/internal/url.js Outdated Show resolved Hide resolved
outURL.hostname = domainToASCII(hostname);
outURL.pathname = encodePathChars(
ArrayPrototypeJoin(ArrayPrototypeSlice(paths, 3), '/'));
StringPrototypeReplaceAll(StringPrototypeSlice(filepath, hostnameEndIndex), '\\', '/'));
Copy link
Member

@anonrig anonrig Dec 24, 2022

Choose a reason for hiding this comment

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

This pull request changes more than just refactoring primordials.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

StringPrototypeSplit relies on user-mutable String.prototype[Symbol.split], so it's not exactly unrelated.

@aduh95
Copy link
Contributor Author

aduh95 commented Dec 25, 2022

Can you also run a benchmark?

FYI that's why I added needs-benchmark-ci PR that need a benchmark CI run. .

@aduh95

This comment was marked as outdated.

@aduh95

This comment was marked as outdated.

@aduh95 aduh95 added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. request-ci Add this label to start a Jenkins CI on a PR. labels Dec 26, 2022
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Dec 26, 2022
@nodejs-github-bot
Copy link
Collaborator

@joyeecheung
Copy link
Member

joyeecheung commented Dec 26, 2022

Do we actually have benchmarks for url.fileURLToPath() and url.pathToFileURL()? I can't find anything after searching in benchmark/, but they are used a lot internally and are what this PR primarily affects now.

Copy link
Member

@joyeecheung joyeecheung left a comment

Choose a reason for hiding this comment

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

We need to benchmark url.fileURLToPath() and url.pathToFileURL(), they are used a lot internally and are affected by this PR

@aduh95

This comment was marked as outdated.

@aduh95

This comment was marked as outdated.

@aduh95

This comment was marked as outdated.

lib/internal/url.js Outdated Show resolved Hide resolved
@aduh95 aduh95 added the request-ci Add this label to start a Jenkins CI on a PR. label Jan 19, 2023
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jan 19, 2023
@nodejs-github-bot
Copy link
Collaborator

@aduh95 aduh95 added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. request-ci Add this label to start a Jenkins CI on a PR. labels Jan 22, 2023
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jan 22, 2023
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@aduh95 aduh95 merged commit e487638 into nodejs:main Jan 22, 2023
@aduh95 aduh95 deleted the url-primordials branch January 22, 2023 13:13
@aduh95
Copy link
Contributor Author

aduh95 commented Jan 22, 2023

Landed in e487638

ruyadorno pushed a commit that referenced this pull request Feb 1, 2023
PR-URL: #45966
Reviewed-By: Zeyu "Alex" Yang <himself65@outlook.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
@ruyadorno ruyadorno mentioned this pull request Feb 1, 2023
juanarbol pushed a commit that referenced this pull request Mar 3, 2023
PR-URL: #45966
Reviewed-By: Zeyu "Alex" Yang <himself65@outlook.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
@juanarbol juanarbol mentioned this pull request Mar 3, 2023
juanarbol pushed a commit that referenced this pull request Mar 5, 2023
PR-URL: #45966
Reviewed-By: Zeyu "Alex" Yang <himself65@outlook.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. needs-benchmark-ci PR that need a benchmark CI run. needs-ci PRs that need a full CI run. whatwg-url Issues and PRs related to the WHATWG URL implementation.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants