url, querystring: optimize serialization and encoding performance#61896
Open
TylerFortune wants to merge 2 commits intonodejs:mainfrom
Open
url, querystring: optimize serialization and encoding performance#61896TylerFortune wants to merge 2 commits intonodejs:mainfrom
TylerFortune wants to merge 2 commits intonodejs:mainfrom
Conversation
- Implement O(N) pre-allocation for URLSearchParams.prototype.toString() - Add string concatenation fast-path for short strings in encodeStr - Align internal serialization with fast-querystring patterns Fixes: nodejs/performance#56
Collaborator
|
Review requested:
|
mcollina
reviewed
Feb 20, 2026
Member
mcollina
left a comment
There was a problem hiding this comment.
Did you run the microbenchmarks you added?
| @@ -0,0 +1,93 @@ | |||
| # Performance Report: URLSearchParams and Querystring Optimization | |||
|
|
|||
| ## 1. Executive Summary | |||
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #61896 +/- ##
==========================================
- Coverage 91.77% 89.77% -2.00%
==========================================
Files 338 674 +336
Lines 140064 204923 +64859
Branches 22045 39392 +17347
==========================================
+ Hits 128543 183972 +55429
- Misses 11298 13229 +1931
- Partials 223 7722 +7499
🚀 New features to boost your workflow:
|
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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR optimizes the performance of
URLSearchParams.prototype.toString()and the internalencodeStrutility used byquerystring.serializeParamsinlib/internal/url.jsto use a pre-allocated array instead of iterative string concatenation. This shifts complexity fromlib/internal/querystring.jsfor strings under 10 characters using direct string concatenation.Technical Details
Performance Results (AMD Ryzen 7)
Detailed data is included in the committed
PERFORMANCE_REPORT.md.Fixes: nodejs/performance#56
Refs: #61896