url: speed up URLPattern - #65364
Open
anonrig wants to merge 1 commit into
Open
Conversation
Avoid extra UTF-8 copies on constructor, test, and exec; construct ASCII V8 strings with NewFromOneByte for regexp matching; and assign URLPatternInit fields by interned key instead of string-comparing each component name. Signed-off-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Yagiz Nizipli <anonrig@users.noreply.github.com> Signed-off-by: Cursor Agent <cursoragent@cursor.com>
Collaborator
|
Review requested:
|
jasnell
requested changes
Aug 18, 2026
jasnell
left a comment
Member
There was a problem hiding this comment.
AI agents are not permitted to use Signed-off-by
jasnell
reviewed
Aug 18, 2026
| length); | ||
| } | ||
| return String::NewFromUtf8( | ||
| isolate, view.data(), NewStringType::kNormal, length); |
Member
There was a problem hiding this comment.
We already have ToV8Value that takes an std::string_view
jasnell
reviewed
Aug 18, 2026
| // and destroy the view before creating any V8 heap objects. | ||
| void CopyV8StringToBuffer(Isolate* isolate, | ||
| Local<String> str, | ||
| MaybeStackBuffer<char>& buffer) { |
Member
There was a problem hiding this comment.
Project convention is to pass pointers when mutating and to only pass refs as const ref
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.
This speeds up WHATWG
URLPatternconstructor,test(), andexec()without changing observable behavior.Independent of the
new URL()parse PR (#65361) and theURLSearchParamsPR (#65363).What changed
C++ only (
src/node_url_pattern.cc):ValueView+memcpyinto a stack buffer and pass astring_viewinto Ada. Drop the extrastd::stringcopy thatBufferValue/Utf8Value::ToString()used to make. Non-ASCII still goes throughUtf8Value.String::NewFromOneByteand useisolate->GetCurrentContext()instead ofEnvironment::GetCurrent.test/exec: share argument parsing so both paths keep the same WebIDL null/undefined/"null"baseURL behavior.Ada still owns its parsed state;
string_views only live for the duration of the C++ call.ValueViewis destroyed before any V8 heap allocation.Tests
test/parallel/test-urlpattern.js,test-urlpattern-types.js,test-urlpattern-invalidthis.js, andtest-urlpattern-fast-path.jsall passtest/wpt/test-urlpattern.js: 743 passed, 0 unexpected failuresLocal benches
Same machine,
n=1e5. Rates in ops/s:https://(sub.)?example(.com/)foo{ hostname }{ pathname, search, hash, baseURL }{ pathname: regexp }{ hostname }{ pathname, search, hash, baseURL }{ pathname: regexp }Constructor is about 3–9% faster;
test()is about 11–12% faster on the non-regexp-heavy cases. Remaining time is Ada parse/match.