Skip to content

querystring: speed up default parse and unescape - #66175

Open
anonrig wants to merge 1 commit into
nodejs:mainfrom
anonrig:cursor/querystring-parse-ead2
Open

anonrig wants to merge 1 commit into
nodejs:mainfrom
anonrig:cursor/querystring-parse-ead2

Conversation

@anonrig

@anonrig anonrig commented Sep 21, 2026

Copy link
Copy Markdown
Member

Skip the %XX walk in unescapeBuffer when the input has no %, and add a dedicated '&'/'=' scanner for the default querystring.parse() path so it does not build separator code arrays or run the multi-character state machine.

Custom separators, maxKeys, decodeURIComponent, and a replaced querystring.unescape still use the existing parser.

This change was implemented with assistance from a closed-source coding agent. I verified the source, official benchmark/querystring results, and test-querystring.js.

Official benches

Three-run medians, n=1e6:

bench main this PR delta
querystring-parse.js encodemany 1.49M 2.05M +38%
querystring-parse.js manyblankpairs 14.8M 17.3M +17%
querystring-parse.js encodelast 2.91M 3.20M +10%
querystring-parse.js noencode 3.86M 4.16M +8%
querystring-unescapebuffer.js (no escapes) 9.73M 13.21M +36%

Tests

test-querystring.js and the other test-querystring-*.js files.

Skip the %XX walk in unescapeBuffer when the input has no '%'.
Add a dedicated '&'/'=' scanner for the default parse path so
it does not build separator code arrays or run the multi-char
state machine.

Official benchmark/querystring/querystring-parse.js:
encodemany is about 38% faster, manyblankpairs about 17%,
encodelast about 10%, noencode about 8%.
Official querystring-unescapebuffer.js with no escapes is
about 36% faster.

Assisted-by: a closed-source coding agent
Signed-off-by: Yagiz Nizipli <yagiz@nizipli.com>
Co-authored-by: Yagiz Nizipli <anonrig@users.noreply.github.com>
@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. querystring Issues and PRs related to the built-in querystring module. labels Sep 21, 2026
@anonrig anonrig added 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 21, 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 21, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@codecov

codecov Bot commented Sep 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.30%. Comparing base (dd5dfb5) to head (824e166).
⚠️ Report is 38 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #66175      +/-   ##
==========================================
+ Coverage   90.27%   90.30%   +0.03%     
==========================================
  Files         790      790              
  Lines      271651   272173     +522     
  Branches    51842    51978     +136     
==========================================
+ Hits       245228   245785     +557     
+ Misses      16928    16885      -43     
- Partials     9495     9503       +8     
Files with missing lines Coverage Δ
lib/querystring.js 100.00% <100.00%> (ø)

... and 59 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.

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

Labels

needs-ci PRs that need a full CI run. querystring Issues and PRs related to the built-in querystring module.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants