url: speed up WHATWG URL parsing - #65361
Conversation
|
Review requested:
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #65361 +/- ##
==========================================
- Coverage 91.85% 90.11% -1.74%
==========================================
Files 400 752 +352
Lines 178855 252356 +73501
Branches 27319 47474 +20155
==========================================
+ Hits 164283 227413 +63130
- Misses 14243 16224 +1981
- Partials 329 8719 +8390
🚀 New features to boost your workflow:
|
jasnell
left a comment
There was a problem hiding this comment.
AI agents are not permitted to Signed-off-by
b9884e1 to
a66b5bc
Compare
|
Removed the |
a66b5bc to
39c4db7
Compare
Parse one-byte ASCII inputs in place instead of copying them into a UTF-8 buffer, and reuse the original V8 string when the serialized href is unchanged. Delay URLContext allocation until parse finishes and skip ToString when the input is already a string. Signed-off-by: Yagiz Nizipli <[email protected]> Assisted-by: Cursor
fa5ca3f to
ed31ad0
Compare
gurgunday
left a comment
There was a problem hiding this comment.
I think we can avoid always comparing the strings here?
Base parsing and setters discard reuse_input, so here we can avoid an O(n) comparison no?
ed31ad0 to
47af16c
Compare
mertcanaltin
left a comment
There was a problem hiding this comment.
LGTM, I think we can seperate PR same improvement for canParse?
faad7a6 to
caa85b0
Compare
Callers that never reuse the original V8 string (base URL parse and setters) now omit reuse_input so ParseUrlFromV8String does not compare href against the input. Signed-off-by: Yagiz Nizipli <[email protected]> Assisted-by: Cursor
caa85b0 to
7589246
Compare
|
Landed in 2df4ce7...a8f9a7f |
Parse one-byte ASCII inputs in place instead of copying them into a UTF-8 buffer, and reuse the original V8 string when the serialized href is unchanged. Delay URLContext allocation until parse finishes and skip ToString when the input is already a string. Signed-off-by: Yagiz Nizipli <[email protected]> Assisted-by: Cursor PR-URL: #65361 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Daniel Lemire <[email protected]> Reviewed-By: Gürgün Dayıoğlu <[email protected]>
Callers that never reuse the original V8 string (base URL parse and setters) now omit reuse_input so ParseUrlFromV8String does not compare href against the input. Signed-off-by: Yagiz Nizipli <[email protected]> Assisted-by: Cursor PR-URL: #65361 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Daniel Lemire <[email protected]> Reviewed-By: Gürgün Dayıoğlu <[email protected]>
Parse one-byte ASCII inputs in place instead of copying them into a UTF-8 buffer, and reuse the original V8 string when the serialized href is unchanged. Delay URLContext allocation until parse finishes and skip ToString when the input is already a string. Signed-off-by: Yagiz Nizipli <[email protected]> Assisted-by: Cursor PR-URL: #65361 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Daniel Lemire <[email protected]> Reviewed-By: Gürgün Dayıoğlu <[email protected]>
Callers that never reuse the original V8 string (base URL parse and setters) now omit reuse_input so ParseUrlFromV8String does not compare href against the input. Signed-off-by: Yagiz Nizipli <[email protected]> Assisted-by: Cursor PR-URL: #65361 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Daniel Lemire <[email protected]> Reviewed-By: Gürgün Dayıoğlu <[email protected]>
Parse one-byte ASCII inputs in place instead of copying them into a UTF-8 buffer, and reuse the original V8 string when the serialized href is unchanged. Delay URLContext allocation until parse finishes and skip ToString when the input is already a string. Signed-off-by: Yagiz Nizipli <[email protected]> Assisted-by: Cursor PR-URL: #65361 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Daniel Lemire <[email protected]> Reviewed-By: Gürgün Dayıoğlu <[email protected]>
Callers that never reuse the original V8 string (base URL parse and setters) now omit reuse_input so ParseUrlFromV8String does not compare href against the input. Signed-off-by: Yagiz Nizipli <[email protected]> Assisted-by: Cursor PR-URL: #65361 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Daniel Lemire <[email protected]> Reviewed-By: Gürgün Dayıoğlu <[email protected]>
Parse one-byte ASCII inputs in place instead of copying them into a UTF-8 buffer, and reuse the original V8 string when the serialized href is unchanged. Delay URLContext allocation until parse finishes and skip ToString when the input is already a string. Signed-off-by: Yagiz Nizipli <[email protected]> Assisted-by: Cursor PR-URL: #65361 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Daniel Lemire <[email protected]> Reviewed-By: Gürgün Dayıoğlu <[email protected]>
Callers that never reuse the original V8 string (base URL parse and setters) now omit reuse_input so ParseUrlFromV8String does not compare href against the input. Signed-off-by: Yagiz Nizipli <[email protected]> Assisted-by: Cursor PR-URL: #65361 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Daniel Lemire <[email protected]> Reviewed-By: Gürgün Dayıoğlu <[email protected]>
Parse one-byte ASCII inputs in place instead of copying them into a UTF-8 buffer, and reuse the original V8 string when the serialized href is unchanged. Delay URLContext allocation until parse finishes and skip ToString when the input is already a string. Signed-off-by: Yagiz Nizipli <[email protected]> Assisted-by: Cursor PR-URL: #65361 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Daniel Lemire <[email protected]> Reviewed-By: Gürgün Dayıoğlu <[email protected]>
Callers that never reuse the original V8 string (base URL parse and setters) now omit reuse_input so ParseUrlFromV8String does not compare href against the input. Signed-off-by: Yagiz Nizipli <[email protected]> Assisted-by: Cursor PR-URL: #65361 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Daniel Lemire <[email protected]> Reviewed-By: Gürgün Dayıoğlu <[email protected]>
Parse one-byte ASCII inputs in place instead of copying them into a UTF-8 buffer, and reuse the original V8 string when the serialized href is unchanged. Delay URLContext allocation until parse finishes and skip ToString when the input is already a string. Signed-off-by: Yagiz Nizipli <[email protected]> Assisted-by: Cursor PR-URL: #65361 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Daniel Lemire <[email protected]> Reviewed-By: Gürgün Dayıoğlu <[email protected]>
Callers that never reuse the original V8 string (base URL parse and setters) now omit reuse_input so ParseUrlFromV8String does not compare href against the input. Signed-off-by: Yagiz Nizipli <[email protected]> Assisted-by: Cursor PR-URL: #65361 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Daniel Lemire <[email protected]> Reviewed-By: Gürgün Dayıoğlu <[email protected]>
Speeds up
new URL()/URL.parse()on the common path: already-serialized ASCII hrefs.The binding currently always:
Utf8Value)href, even when it is byte-identical to the inputTypical URLs (
https://example.com/path, thewhatwg-url-parsebenchmark corpus) are one-byte ASCII and already in serialized form. This change:v8::String::ValueView(no UTF-8 copy)href == input(no second string allocation)std::stringjust to parse itupdate()(setters re-parse an already-serialized href)URLContextallocation until parse finishes, and initializes it in one shot fromurlComponents`${input}`when the value is already a stringNon-ASCII inputs still go through
Utf8Value. Those results are never reused as the original string, because UTF-8 conversion may replace unpaired surrogates.Benchmark
Same machine, Release build,
benchmark/url/whatwg-url-parse.js e=12. Repeated runs:short/ no baselong/ no baseshort/ with basedot(needs path normalization, so a new href string) is unchanged.Review follow-up
reuse_inputdefaults tonullptr. Base-URL parse andupdate()omit it so we skip the O(n)href == inputcompare when the original V8 string will not be reused.Tests
test/parallel/test-whatwg-url-*.jsandtest-url-*.js: 54 pass, 1 skipurl: 5107 pass, 0 unexpected failurestest/parallel/test-whatwg-url-parse-fast-path.jscovers already-serialized ASCII hrefs, trailing-slash and dot-segment normalization, base resolution, non-string input, invalid input, unpaired surrogates, IDN, and settersAssisted-by: Cursor