WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
NEW
271735
URL.searchParams eagerly re-parses the URL, which can be slow when making many updates in a row
https://bugs.webkit.org/show_bug.cgi?id=271735
Summary
URL.searchParams eagerly re-parses the URL, which can be slow when making man...
Matt Cowley
Reported
2024-03-26 16:10:52 PDT
👋 It seems that WebKit suffers from the same performance issue that I fixed in Node.js (
https://github.com/nodejs/node/pull/51520
), where repeat writes to `URL.searchParams` trigger `URL` to re-parse the params on every write, leading to a performance bottleneck. ```js // Will lock up the browser const params = new URL('
https://mozilla.org').searchParams
; for (let i = 0; i < 100_000; i++) params.append('test', i.toString()); ``` ```js // Will run without issue const params = new URLSearchParams(); for (let i = 0; i < 100_000; i++) params.append('test', i.toString()); ``` I suspect a patch similar to what I landed in Node.js, where URL is lazily updated if searchParams has changed the next time a getter is called, rather than immediately updating URL when searchParams changes, would fix it.
Attachments
Add attachment
proposed patch, testcase, etc.
Matt Cowley
Comment 1
2024-03-26 16:20:54 PDT
I was reading through
https://github.com/WebKit/WebKit/blob/main/Source/WebCore/html/DOMURL.cpp
+
https://github.com/WebKit/WebKit/blob/main/Source/WebCore/html/URLSearchParams.cpp
to see if I could figure out making a patch myself to apply a similar fix as I did in Node.js (I'm not familiar with C++ particularly), and I see where the call back to URL happens from URLSearchParams when it is updated (URLSearchParams::updateURL), but what I couldn't figure out is where all the getters/setters are for URL that would need to ensure the lazy update occurs?
Alexey Proskuryakov
Comment 2
2024-03-27 17:44:21 PDT
Looks like those are in URLSearchParams.cpp - you can see updateURL() calls which would need to turn into lazy updates. That said, while lazy update will obviously make this operation faster, it would make all read operations slower due to adding a branch. So performance testing would need to be done to make sure that such an optimization doesn't degrade user experience in regular browsing.
Anne van Kesteren
Comment 3
2024-03-28 02:44:15 PDT
I suspect Matt is also looking for Source/WebCore/html/URLDecomposition.cpp? I would expect the majority usage of URLSearchParams on the web to be for reading. Definitely have to be careful here.
Radar WebKit Bug Importer
Comment 4
2024-04-02 16:11:11 PDT
<
rdar://problem/125809780
>
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug