Skip to content

deps: replace url parser with Ada - #46410

Closed
anonrig wants to merge 2 commits into
nodejs:mainfrom
anonrig:deps/ada
Closed

deps: replace url parser with Ada#46410
anonrig wants to merge 2 commits into
nodejs:mainfrom
anonrig:deps/ada

Conversation

@anonrig

@anonriganonrig commented Jan 29, 2023

Copy link
Copy Markdown
Member

This work was done in collaboration with me, @miguelteixeiraa and @lemire. I would also like to thank @addaleax and @ronag for their help.

This pull request replaces the existing URL parser with Ada, a fast spec-compliant URL parser written from scratch using modern C++ focused on performance.

A little bit about Ada:

  • 100% spec compliant (even has its own WPT updater, which led us to find a couple of errors in WPT)
  • Fully tested (using both web platform tests, custom tests not covered by WPT) on Big Endian Systems (s390x), Ubuntu 20.04, Ubuntu 22.04 (with G++ and Clang++), Windows VS 2022 (with and without ClangCL)
  • Well documented and available for the public at https://ada-url.github.io/ada
  • On typical URLs, we use between 50 and 60 instructors per input byte for fully parsing and validating a URL string into a URL data structure.

The possibilities with this pull request:

Side Note: Current benchmarks show up to 87% faster URL parsing, with similar but sometimes faster execution speeds compared to url.parse.

Fixes#46332
Fixes#46063
Fixes#30334
Fixes#44476
Fixesnodejs/performance#33
Closes#41220

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/crypto
  • @nodejs/gyp
  • @nodejs/loaders
  • @nodejs/modules
  • @nodejs/node-api
  • @nodejs/tsc
  • @nodejs/vm

@nodejs-github-botnodejs-github-bot added lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Jan 29, 2023
@anonrig
anonrigforce-pushed the deps/ada branch 9 times, most recently from 8f4d1a4 to 4a68c84CompareJanuary 30, 2023 02:37

@mcollinamcollina 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.

Something that I think should be experimented upon is to avoid copying all data back-and-forth every time a field is updated.

Maybe it might be better to fetch them from C++ every time they are accessed, or possibly use tricks to use the V8 fast API.

@anonrig
anonrigforce-pushed the deps/ada branch 3 times, most recently from 21adb01 to 6f070dcCompareJanuary 30, 2023 17:28
@anonriganonrig mentioned this pull request Jan 30, 2023
@joyeecheung

Copy link
Copy Markdown
Member

Deprecating url.parse

I think that has always been possible, with or without Ada? It's kept for compatibility reasons, not performance.

Removes the need to update and conform to URL WPT

We probably still want to run the JS tests to make sure that the JS glues work properly

@anonrig

Copy link
Copy Markdown
MemberAuthor

We probably still want to run the JS tests to make sure that the JS glues work properly

You're right. This pull request does not remove them.

@anonrig
anonrigforce-pushed the deps/ada branch 2 times, most recently from 5e1e1ac to a1c7401CompareJanuary 30, 2023 20:35
@anonrig

Copy link
Copy Markdown
MemberAuthor

test/sequential/test-inspector.js test is failing. Appreciate any help in pinpointing why it causes timeouts. cc @targos@Trott@addaleax (according to git blame, you were the only ones who worked on this file in the last 3 years)

@MoLow

Copy link
Copy Markdown
Member

@anonrig it might very well be related to parsing the debugger websocket url

@anonrig
anonrigforce-pushed the deps/ada branch 5 times, most recently from eb45d67 to 17d3ed7CompareFebruary 1, 2023 19:14
@TimothyGu

Copy link
Copy Markdown
Member

I see right now Ada has Windows-specific IDNA handling using IdnToAscii. I'm a little concerned about this, as it would introduce platform-dependent URL parsing results. I also doubt Windows's IdnToAscii implements UTS46 fully.

I see plans to switch to an internal implementation (ada-url/ada#89) which would alleviate my concern. Do note though, that there are (still) outstanding issues with UTS46 on the spec side (see whatwg/url#744).

(Context: I helped create the previous WHATWG URL parser, and also maintain https://github.com/jsdom/tr46.)

@lemire

lemire commented Feb 1, 2023

Copy link
Copy Markdown
Member

I see right now Ada has Windows-specific IDNA handling using IdnToAscii.

When ICU is unavailable and we are under Windows, then ada falls back on Windows functions. That is correct.

Wherever we are, if ICU is available, we rely on ICU.

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Landed in 4c08c20...c4581ab

nodejs-github-bot pushed a commit that referenced this pull request Feb 6, 2023
PR-URL: #46410
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
nodejs-github-bot pushed a commit that referenced this pull request Feb 6, 2023
PR-URL: #46410
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
@richardlaurichardlau added the baking-for-lts PRs that need to wait before landing in a LTS release. label Feb 6, 2023
@richardlau

Copy link
Copy Markdown
Member

@nodejs/lts I've put baking-for-ltsPRs that need to wait before landing in a LTS release. on this -- I feel we should err on the side of caution and allow more time for this in current releases before considering for LTS.

tniessen added a commit to tniessen/node that referenced this pull request Feb 7, 2023
MylesBorins pushed a commit that referenced this pull request Feb 18, 2023
PR-URL: #46410
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
@MylesBorinsMylesBorins mentioned this pull request Feb 19, 2023
@zloirockzloirock mentioned this pull request Feb 21, 2023
@anonrig

Copy link
Copy Markdown
MemberAuthor

@nodejs/lts I've put baking-for-lts PRs that need to wait before landing in a LTS release. on this -- I feel we should err on the side of caution and allow more time for this in current releases before considering for LTS.

@richardlau Should we remove the backing-for-lts label? In total, there were 2 issues reported and all of them is fixed in 19.8.0.

@richardlau

Copy link
Copy Markdown
Member

@nodejs/lts I've put baking-for-lts PRs that need to wait before landing in a LTS release. on this -- I feel we should err on the side of caution and allow more time for this in current releases before considering for LTS.

@richardlau Should we remove the backing-for-lts label? In total, there were 2 issues reported and all of them is fixed in 19.8.0.

@nodejs/lts thoughts?

@targos

Copy link
Copy Markdown
Member

I'd be ok for a backport to active v18.x, not earlier.

@danielleadams

Copy link
Copy Markdown
Contributor

@anonrig this will need a backport to v18.x.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author readyPRs that have at least one approval, no pending requests for changes, and a CI started.commit-queue-rebaseAdd this label to allow the Commit Queue to land a PR in several commits.lib / srcIssues and PRs related to general changes in the lib or src directory.needs-ciPRs that need a full CI run.notable-changePRs with changes that should be highlighted in changelogs.review wantedPRs that need reviews.

Projects

None yet

18 participants

@anonrig@nodejs-github-bot@joyeecheung@MoLow@TimothyGu@lemire@Trott@targos@radekg@richardlau@danielleadams@mcollina@dougwilson@bmeck@jasnell@benjamingr@ronag@RafaelGSS