Skip to content

url: speed up setters, search params, and URLPattern - #66188

Open
anonrig wants to merge 2 commits into
nodejs:mainfrom
anonrig:url-hot-paths
Open

anonrig wants to merge 2 commits into
nodejs:mainfrom
anonrig:url-hot-paths

Conversation

@anonrig

@anonrig anonrig commented Sep 21, 2026

Copy link
Copy Markdown
Member

Why

URL setters always reparsed the href, including when the assigned value was already the serialized component. URLSearchParams built from a record walked Reflect.ownKeys, and every get / has converted the name again. URL.canParse and URLPattern.test took the slow string callback for ASCII input.

What

A setter skips ada when the new value matches the component already stored on the href, and skips the slice when the lengths differ. An empty host or hostname, and a lone ? or #, still go through ada, because those writes are not idempotent. Record URLSearchParams uses Object.keys when there are no symbol keys. Repeated get, getAll, and has of the same string skip a second USVString conversion. URL.canParse and URLPattern.prototype.test use the one-byte fast API; two-byte strings stay on the slow path.

benchmark/compare.js --runs 5 on macOS arm64 Release, against the parent commit built with the same toolchain. Stars in that tool mark a significant difference; the rows below are significant. Assigning the current pathname on its own went from 3.9M to 106M ops/s. Setting a different pathname was flat (+3%).

Benchmark Change
whatwg-url-properties href, with base +150%
whatwg-url-properties password, with base +118%
whatwg-url-properties port, with base +113%
whatwg-url-properties protocol, with base +110%
whatwg-url-properties username, with base +108%
whatwg-url-properties pathname, with base +76%
whatwg-url-properties host, with base +71%
whatwg-url-properties hash, with base +64%
whatwg-url-properties search, with base +62%
whatwg-url-properties hostname, with base +55%
whatwg-url-canParse long +54%
whatwg-url-canParse short +45%
whatwg-url-canParse ws +29%
whatwg-url-canParse file +28%
whatwg-url-canParse javascript +28%
whatwg-url-canParse auth +19%
url-searchparams-creation object, noencode +68%
url-searchparams-read has one +88%
url-searchparams-read get one +79%
urlpattern-test exact pathname/search/hash +32%
urlpattern-test hostname +32%

test/parallel/test-whatwg-url*, test-urlpattern*, test-url*, and WPT url / urlpattern pass. A closed-source coding agent assisted with the implementation.

Skip the ada reparse when a setter is given the value already stored
on the URL, and skip the component slice when the lengths differ.
Empty host and a lone "?" or "#" still go through ada, because those
assignments are not idempotent.

URLSearchParams records with no symbol keys use Object.keys. Repeated
get, getAll, and has of the same string skip a second USVString
conversion. URL.canParse and URLPattern.prototype.test use the
one-byte fast API.

Signed-off-by: Yagiz Nizipli <yagiz@nizipli.com>
@nodejs-github-bot

Copy link
Copy Markdown
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++. lib / src Issues and PRs involving general changes in the lib/ or src/ directories. needs-ci PRs that need a full CI run. labels Sep 21, 2026
Debug builds count url.canParse and url.canParse.withBase. The
one-byte fast path renamed those keys, so the shared debug jobs
saw a count of 0.

Signed-off-by: Yagiz Nizipli <yagiz@nizipli.com>
@codecov

codecov Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 78.64078% with 66 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.28%. Comparing base (67a4416) to head (078b443).
⚠️ Report is 102 commits behind head on main.

Files with missing lines Patch % Lines
src/node_url_pattern.cc 49.35% 35 Missing and 4 partials ⚠️
lib/internal/url.js 92.27% 15 Missing and 1 partial ⚠️
src/node_url.cc 56.00% 10 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #66188      +/-   ##
==========================================
- Coverage   90.28%   90.28%   -0.01%     
==========================================
  Files         790      790              
  Lines      272044   272231     +187     
  Branches    51949    51990      +41     
==========================================
+ Hits       245625   245782     +157     
- Misses      16915    16966      +51     
+ Partials     9504     9483      -21     
Files with missing lines Coverage Δ
src/node_url.h 100.00% <ø> (ø)
src/node_url_pattern.h 0.00% <ø> (ø)
src/node_url.cc 77.80% <56.00%> (-1.15%) ⬇️
lib/internal/url.js 92.83% <92.27%> (-0.44%) ⬇️
src/node_url_pattern.cc 77.25% <49.35%> (-6.28%) ⬇️

... and 20 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jasnell

jasnell commented Sep 21, 2026

Copy link
Copy Markdown
Member

The test coverage gaps in this should be looked at

@panva panva added author ready PRs with CI started, the required approvals, and no outstanding review comments. request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. labels Sep 24, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Sep 24, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@panva panva added commit-queue-squash PRs the Commit Queue should land as one squashed commit. commit-queue PRs queued for automated landing through the Commit Queue. labels Sep 25, 2026
@nodejs-github-bot nodejs-github-bot added lacks-second-approval Commit Queue PRs awaiting a second collaborator approval or completion of the required wait. commit-queue-failed PRs whose Commit Queue landing failed and need manual intervention before retrying. and removed commit-queue PRs queued for automated landing through the Commit Queue. lacks-second-approval Commit Queue PRs awaiting a second collaborator approval or completion of the required wait. labels Sep 25, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Commit Queue failed

   ⚠  Could not retrieve the email or name of the PR author's from user's GitHub profile!
   ✖  This PR needs to wait 80 more hours to land (or 0 minutes if there is one more approval)
   ⚠  This PR has conflicts that must be resolved

The pull request was removed from the Commit Queue and labeled commit-queue-failed PRs whose Commit Queue landing failed and need manual intervention before retrying. . After resolving the failure, remove that label and add commit-queue PRs queued for automated landing through the Commit Queue. to retry.

Full Commit Queue output
�[36m⠋�[39m Loading data for nodejs/node/pull/66188
�[36m⠋�[39m Loading data for nodejs/node/pull/66188
�[36m⠋�[39m Getting collaborator contacts from README of nodejs/node
�[36m⠋�[39m Getting PR from nodejs/node/pull/66188
�[36m⠋�[39m Getting reviews from nodejs/node/pull/66188
�[36m⠋�[39m Getting comments from nodejs/node/pull/66188
�[36m⠋�[39m Getting commits from nodejs/node/pull/66188
✔  Done loading data for nodejs/node/pull/66188
----------------------------------- PR info ------------------------------------
Title      url: speed up setters, search params, and URLPattern (#66188)
   ⚠  Could not retrieve the email or name of the PR author's from user's GitHub profile!
Branch     anonrig:url-hot-paths -> nodejs:main
Labels     c++, lib / src, author ready, needs-ci, commit-queue, commit-queue-squash, lacks-second-approval
Commits    2
 - url: speed up setters, search params, and URLPattern
 - url: restore canParse fast-api counter names
Committers 1
 - Yagiz Nizipli <yagiz@nizipli.com>
PR-URL: https://github.com/nodejs/node/pull/66188
Reviewed-By: James M Snell <jasnell@gmail.com>
------------------------------ Generated metadata ------------------------------
PR-URL: https://github.com/nodejs/node/pull/66188
Reviewed-By: James M Snell <jasnell@gmail.com>
--------------------------------------------------------------------------------
   ℹ  This PR was created on Mon, 21 Sep 2026 21:12:39 GMT
   ✔  Approvals: 1
   ✔  - James M Snell (@jasnell) (TSC): https://github.com/nodejs/node/pull/66188#pullrequestreview-5272623153
   ✖  This PR needs to wait 80 more hours to land (or 0 minutes if there is one more approval)
   ⚠  This PR has conflicts that must be resolved
   ✔  Last GitHub CI successful
   ℹ  Last Full PR CI on 2026-09-24T20:24:13Z: https://ci.nodejs.org/job/node-test-pull-request/77862/
�[36m⠙�[39m Querying data for job/node-test-pull-request/77862/
�[36m⠙�[39m Querying data for job/node-test-pull-request/77862/
�[36m⠙�[39m Querying API for job/node-test-pull-request/77862/
✔  Build data downloaded
   ✔  Last Jenkins CI successful
--------------------------------------------------------------------------------
   ✔  Aborted `git node land` session in /home/runner/work/node/node/.ncu

View workflow run

@github-actions github-actions Bot removed the author ready PRs with CI started, the required approvals, and no outstanding review comments. label Sep 26, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This pull request has conflicts with its base branch, removing the author ready label.
Please rebase your branch onto the latest base branch, resolve the conflicts locally, and force-push.
Afterwards the pull request needs a fresh collaborator approval, and a collaborator will add the label back once it is author ready again.

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++. commit-queue-failed PRs whose Commit Queue landing failed and need manual intervention before retrying. commit-queue-squash PRs the Commit Queue should land as one squashed commit. lib / src Issues and PRs involving general changes in the lib/ or src/ directories. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants