FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

esm: avoid try/catch when validating urls by anonrig · Pull Request #47541 · nodejs/node · GitHub

/ node Public

esm: avoid try/catch when validating urls - #47541

Merged
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
anonrig:improve-esm-performance
Apr 15, 2023
Merged

esm: avoid try/catch when validating urls#47541
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
anonrig:improve-esm-performance

Conversation

anonrig commented Apr 13, 2023

Copy link
Copy Markdown
Member

Due to URL.canParse, we can avoid try/catch block and have faster validation. The previous implementation was not performant due to:

  1. Unnecessary string serialization - We don't need href, origin etc. for validating if a URL is valid or not.
  2. URL.canParse can be written with V8 Fast API - enabling more performance out of this pull request.
  3. URL.canParse does not return anything except a boolean.

cc @nodejs/url

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/loaders
  • @nodejs/modules

nodejs-github-bot added esm Issues and PRs related to the ECMAScript Modules implementation. needs-ci PRs that need a full CI run. labels Apr 13, 2023

aduh95 left a comment
edited
Loading

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Given that URL.canParse is user-mutable, should we use const { canParse } = URL or something like that? Or even better, can we import it primordial-style from ada directly?

anonrig commented Apr 13, 2023

Copy link
Copy Markdown
Member Author

Given that URL.canParse is user-mutable, should we use const { canParse } = URL or something like that? Or even better, can we import it primordial-style from ada directly?

@aduh95 I like where this is going, but I couldn't visualize it. Can you elaborate on how we can import it primordial-style? We can always do const { canParse } = internalBinding('url'); if that's what you are recommending?

aduh95 commented Apr 13, 2023

Copy link
Copy Markdown
Contributor

Yes, I mean something that's available only internally and cannot be mutated at runtime. const { canParse } = internalBinding('url') is close enough, let's roll with this :)

anonrig force-pushed the improve-esm-performance branch from 5375959 to 3a57762 Compare April 13, 2023 15:52
anonrig requested a review from aduh95 April 13, 2023 15:53
anonrig added author ready PRs that have at least one approval, no outstanding review comments, and a CI started. request-ci Add this label to start a Jenkins CI on a PR. labels Apr 13, 2023
github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Apr 13, 2023

Copy link
Copy Markdown
Collaborator

ljharb commented Apr 13, 2023

Copy link
Copy Markdown
Member

This is way better/cleaner :-) but does it prevent backporting this commit, since older release lines may not have URL.canParse?

anonrig commented Apr 13, 2023

Copy link
Copy Markdown
Member Author

This is way better/cleaner :-) but does it prevent backporting this commit, since older release lines may not have URL.canParse?

It might make it harder, due to conflicts, but I don't think it will block backporting any future changes to ESM.

ljharb commented Apr 13, 2023

Copy link
Copy Markdown
Member

oh sure, i just meant, should this PR have any "do not backport" labels, or link to the canParse PR as a prereq?

anonrig commented Apr 13, 2023

Copy link
Copy Markdown
Member Author

oh sure, i just meant, should this PR have any "do not backport" labels, or link to the canParse PR as a prereq?

I'm not quite sure. @nodejs/releasers what do you recommend?

JakobJingleheimer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Sweet, thanks! I was just suggesting this change last night in Slack 😁

aduh95 commented Apr 13, 2023

Copy link
Copy Markdown
Contributor

oh sure, i just meant, should this PR have any "do not backport" labels, or link to the canParse PR as a prereq?

canParse was added in #47179, and there's no labels that says the backport is blocked, so no action should be necessary here I think. PRs are backported in the order they landed on Current release lines, precisely because it's often the case that a PR builds on top of another one.

mscdex commented Apr 13, 2023

Copy link
Copy Markdown
Contributor

2. URL.canParse can be written with V8 Fast API - enabling more performance out of this pull request.

I'm confused by this. The C++ API still says this:

node/src/node_url.cc

Lines 116 to 117 in 4afb25c

// TODO(@anonrig): Add V8 Fast API for CanParse method
void BindingData::CanParse(const FunctionCallbackInfo<Value>& args) {

Or did you actually mean this PR does not improve performance until the TODO is resolved?

anonrig commented Apr 13, 2023

Copy link
Copy Markdown
Member Author

Or did you actually mean this PR does not improve performance until the TODO is resolved?

I was giving some context to this particular change. It is definitely faster than the current implementation. Additionally, @KhafraDev just opened a pull request for adding v8 fast API to canParse #47552

ljharb commented Apr 13, 2023

Copy link
Copy Markdown
Member

@aduh95 perfect, thanks for clarifying and linking :-)

anonrig force-pushed the improve-esm-performance branch from 3a57762 to 05742e9 Compare April 14, 2023 13:45
anonrig added the request-ci Add this label to start a Jenkins CI on a PR. label Apr 14, 2023
github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Apr 14, 2023

Copy link
Copy Markdown
Collaborator

Copy link
Copy Markdown
Collaborator

anonrig commented Apr 14, 2023

Copy link
Copy Markdown
Member Author

Would someone re-review this pull request? It's required due to force-push.

anonrig added the commit-queue Add this label to land a pull request using GitHub Actions. label Apr 14, 2023
} = require('internal/errors').codes;
const { exitCodes: { kUnfinishedTopLevelAwait } } = internalBinding('errors');
const { URL } = require('internal/url');
const { canParse: urlCanParse } = internalBinding('url');

JakobJingleheimer Apr 15, 2023
edited
Loading

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

nit: this sounds a little Yoda-esque

Suggested change
const { canParse: urlCanParse } = internalBinding('url');
const { canParse: canParseURL } = internalBinding('url');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Not sure this is better, isURLString might be more suited. URLCanParse has the upside of being consistent with how primordials are named, which is nice imho

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I want to change this to URLCanParse too but I'm too demotivated by having to run Node.js CI multiple times because of the flaky tests.

nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Apr 15, 2023
nodejs-github-bot merged commit 17570c0 into nodejs:main Apr 15, 2023

Copy link
Copy Markdown
Collaborator

Landed in 17570c0

targos pushed a commit that referenced this pull request May 2, 2023
PR-URL: #47541
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
targos mentioned this pull request May 2, 2023
targos pushed a commit to targos/node that referenced this pull request Nov 11, 2023
PR-URL: nodejs#47541
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
targos pushed a commit that referenced this pull request Nov 23, 2023
PR-URL: #47541
Backport-PR-URL: #50669
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
sercher added a commit to sercher/graaljs that referenced this pull request Apr 25, 2024
PR-URL: nodejs/node#47541
Backport-PR-URL: nodejs/node#50669
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
sercher added a commit to sercher/graaljs that referenced this pull request Apr 25, 2024
PR-URL: nodejs/node#47541
Backport-PR-URL: nodejs/node#50669
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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 outstanding review comments, and a CI started. esm Issues and PRs related to the ECMAScript Modules implementation. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants


Back | FazBrowse Home | New Git URL