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: improve invalid url performance #49692

Merged

Conversation

anonrig
Copy link
Member

@anonrig anonrig commented Sep 17, 2023

Some easy wins for Invalid URL path.

                                                    confidence improvement accuracy (*)   (**)  (***)
url/whatwg-url-validity.js e=100000 type='invalid'        ***    120.33 %       ±2.06% ±2.74% ±3.56%
url/whatwg-url-validity.js e=100000 type='valid'                   1.35 %       ±2.21% ±2.96% ±3.91%

Be aware that when doing many comparisons the risk of a false-positive result increases.
In this case, there are 2 comparisons, you can thus expect the following amount of false-positive results:
  0.10 false positives, when considering a   5% risk acceptance (*, **, ***),
  0.02 false positives, when considering a   1% risk acceptance (**, ***),
  0.00 false positives, when considering a 0.1% risk acceptance (***)

cc @nodejs/url @nodejs/performance

@anonrig anonrig added performance Issues and PRs related to the performance of Node.js. whatwg-url Issues and PRs related to the WHATWG URL implementation. labels Sep 17, 2023
@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/url

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. labels Sep 17, 2023
@anonrig anonrig force-pushed the improve-invalid-url-performance branch from 0501c68 to 79415ed Compare September 17, 2023 21:36
@anonrig anonrig added the semver-major PRs that contain breaking changes and should be released in the next major version. label Sep 17, 2023
@anonrig
Copy link
Member Author

anonrig commented Sep 17, 2023

@nodejs/tsc I've removed the error.input from URL error - ERR_INVALID_URL to make sure we share a similar output with Chrome and Safari. I've also added semver-major label because of the removal of error.input attribute.

Safari returns: TypeError: Type error
Chrome returns: VM78:1 Uncaught TypeError: Failed to construct 'URL': Invalid URL

None of them have the error.input attribute.

@aduh95
Copy link
Contributor

aduh95 commented Sep 17, 2023

I would keep the input, and even add the base, it can very hard to understand what is the error without seeing the input and base

lib/internal/errors.js Outdated Show resolved Hide resolved
@rluvaton rluvaton added the needs-benchmark-ci PR that need a benchmark CI run. label Sep 18, 2023
@rluvaton
Copy link
Member

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

@aduh95
Copy link
Contributor

aduh95 commented Sep 18, 2023

Could there be a way to get the same performance improvements without removing helpful debugging information? If not, maybe we could use a flag to opt-in to the slower option that outputs the input and base?

@anonrig
Copy link
Member Author

anonrig commented Sep 18, 2023

Could there be a way to get the same performance improvements without removing helpful debugging information? If not, maybe we could use a flag to opt-in to the slower option that outputs the input and base?

Probably, although I'm not sure. This requires a similar approach to what ThrowAccessDenied is doing in https://github.com/nodejs/node/blob/main/src/permission/permission.cc#L102.

@anonrig anonrig added the request-ci Add this label to start a Jenkins CI on a PR. label Sep 18, 2023
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Sep 18, 2023
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@tniessen
Copy link
Member

FWIW, I tend to agree with @aduh95 that removing error information for the sake of performance (on an error path!) does not benefit users. I thought that URL.canParse() was specifically added to avoid having to rely on the performance of the URL error path.

@Uzlopak
Copy link
Contributor

Uzlopak commented Sep 19, 2023

How much is actually the performance hit when keeping the input as an attribute?

Copy link
Member

@BridgeAR BridgeAR left a comment

Choose a reason for hiding this comment

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

I do not think it's a good idea to remove important debug information in favor of performance. We can definitely improve the performance but debug information is more important. I had an open PR to improve the situation a lot and I have to get back to that again.

@anonrig anonrig force-pushed the improve-invalid-url-performance branch from 147dd75 to a9c408a Compare September 19, 2023 22:30
@anonrig
Copy link
Member Author

anonrig commented Sep 19, 2023

@BridgeAR @aduh95 @tniessen I've updated the implementation. Previously this pull request was 142% faster than main. Right now it is 120% faster. I also added base field to the error object.

Appreciate it, if you can review it once again.

@anonrig anonrig force-pushed the improve-invalid-url-performance branch from 29267d9 to c59b136 Compare September 19, 2023 22:38
@anonrig anonrig added the request-ci Add this label to start a Jenkins CI on a PR. label Sep 20, 2023
@anonrig anonrig removed the semver-major PRs that contain breaking changes and should be released in the next major version. label Sep 20, 2023
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Sep 20, 2023
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@anonrig
Copy link
Member Author

anonrig commented Sep 22, 2023

Hey @BridgeAR, can you re-review this pull request, and remove your block?

@benjamingr
Copy link
Member

I suspect he would still object since the URL isn't part of the message string, what's the cost of adding that back?

@anonrig
Copy link
Member Author

anonrig commented Sep 23, 2023

I suspect he would still object since the URL isn't part of the message string, what's the cost of adding that back?

I don't follow. URL was never part of the message string? Input is a property of the error object. On top of that I've also added base property to the error as well.

@benjamingr
Copy link
Member

@anonrig ah, I'm probably mixing it up with another PR then, lgtm

@anonrig anonrig added the tsc-agenda Issues and PRs to discuss during the meetings of the TSC. label Sep 26, 2023
@anonrig
Copy link
Member Author

anonrig commented Sep 26, 2023

Adding to @nodejs/tsc agenda to resolve the block.

@targos
Copy link
Member

targos commented Sep 26, 2023

There's no need for the TSC to intervene if you addressed the blocking comment

@anonrig anonrig dismissed BridgeAR’s stale review September 26, 2023 15:32

The comment is addressed.

@anonrig anonrig added commit-queue Add this label to land a pull request using GitHub Actions. and removed tsc-agenda Issues and PRs to discuss during the meetings of the TSC. labels Sep 26, 2023
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Sep 26, 2023
@nodejs-github-bot nodejs-github-bot merged commit c829c03 into nodejs:main Sep 26, 2023
30 checks passed
@nodejs-github-bot
Copy link
Collaborator

Landed in c829c03

ruyadorno pushed a commit that referenced this pull request Sep 28, 2023
PR-URL: #49692
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
@ruyadorno ruyadorno mentioned this pull request Sep 28, 2023
ruyadorno pushed a commit that referenced this pull request Sep 28, 2023
PR-URL: #49692
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
@ruyadorno ruyadorno mentioned this pull request Sep 28, 2023
alexfernandez pushed a commit to alexfernandez/node that referenced this pull request Nov 1, 2023
PR-URL: nodejs#49692
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
debadree25 pushed a commit to debadree25/node that referenced this pull request Apr 15, 2024
PR-URL: nodejs#49692
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. needs-benchmark-ci PR that need a benchmark CI run. needs-ci PRs that need a full CI run. performance Issues and PRs related to the performance of Node.js. whatwg-url Issues and PRs related to the WHATWG URL implementation.
Projects
None yet
Development

Successfully merging this pull request may close these issues.