-
Notifications
You must be signed in to change notification settings - Fork 29.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Performance issue with URL.searchParams.append for large numbers of params #51518
Comments
(unrelated to Node.js, but bonus points to anyone that feels like surfacing a similar fix with browser engines, as they seem to suffer from the same bottleneck) |
As I understand it currently, Thinking through this, I think the approach to fixing this might be:
This does mean that the internal |
@anonrig @nodejs/performance |
PR-URL: #51520 Fixes: #51518 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
PR-URL: nodejs#51520 Fixes: nodejs#51518 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
PR-URL: nodejs#51520 Fixes: nodejs#51518 Backport-PR-URL: nodejs#51559 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
PR-URL: nodejs#51520 Fixes: nodejs#51518 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
PR-URL: nodejs#51520 Fixes: nodejs#51518 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
PR-URL: #51520 Fixes: #51518 Backport-PR-URL: #51559 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
PR-URL: nodejs#51520 Fixes: nodejs#51518 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
PR-URL: #51520 Fixes: #51518 Backport-PR-URL: #51559 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
PR-URL: #51520 Fixes: #51518 Backport-PR-URL: #51559 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
Version
21.6.0
Platform
Darwin [snip] 23.2.0 Darwin Kernel Version 23.2.0: Wed Nov 15 21:53:18 PST 2023; root:xnu-10002.61.3~2/RELEASE_ARM64_T6000 arm64
Subsystem
No response
What steps will reproduce the bug?
Using
URL.searchParams.append
:vs. using
URLSearchParams.append
:How often does it reproduce? Is there a required condition?
No response
What is the expected behavior? Why is that the expected behavior?
No response
What do you see instead?
The
URL.searchParams.append
snippet with 50,000 params being append takes 2-3 minutes to run on an M1, which is a ridiculous amount of time. The equivalent snippet withURLSearchParams.append
takes 50-100 milliseconds to run.Additional information
I talked through this performance issue with Yagiz on Twitter and got to what appears to be the cause of the issue, every time
URL.searchParams.append
is called, the whole URL essentially gets stringified to update properties onURL
itself: https://twitter.com/yagiznizipli/status/1748151781534650545I believe it to be this call that is the cause:
node/lib/internal/url.js
Lines 478 to 480 in eb4432c
With
#context
being set here:node/lib/internal/url.js
Lines 1023 to 1024 in eb4432c
And the
#context.search
setter being here:node/lib/internal/url.js
Lines 1012 to 1017 in eb4432c
I'm unsure whether the performance issue is with the
toString
call inURLSearchParams
, or whether it is within the logic of the#context.search
setter. I've not worked with Node.js source before, so not sure where to start on profiling that, or submitting a fix (hence opening this issue to track it for anyone to grab).I suspect that an "easy" fix either way is to update
URLSearchParams
such that it doesn't write back toURL
, and instead update the relevant bits ofURL
(href
,search
, etc.) to essentially call the logic that is currently in the#context.search
setter on-demand as getters when needed, ifURLSearchParams
has been created for theURL
.The text was updated successfully, but these errors were encountered: