Repository navigation
Conversation
Avoid extra UTF-8 copies on constructor, test, and exec; convert regexp inputs with ToV8Value; and assign URLPatternInit fields by interned key instead of string-comparing each component name. Signed-off-by: Yagiz Nizipli <yagiz@nizipli.com> Assisted-by: Cursor
Signed-off-by: Daniel Lemire <daniel@lemire.me> # Conflicts: # src/node_url_pattern.cc
Rework the URLPattern speed-up on top of main: - Reuse ParseURLPatternMatchArgs and keep the lexicographic order of URLPatternInit members. Pair each key with the field it fills. - Keep a Utf8Value alive for the call instead of copying string inputs into a std::string. - Read the current context directly in the regex provider instead of going through Environment::GetCurrent(). - Build exec() `groups` as an ordinary object whose prototype is Object.prototype. Previously each one got a fresh prototype object, which forced V8 to create new maps on every call and departed from WebIDL. Add tests for Latin-1 and two-byte string inputs and for the prototype of `groups`, and a benchmark for exec() with a match. Signed-off-by: Daniel Lemire <daniel@lemire.me>
cursor
Bot
force-pushed
the
cursor/urlpattern-performance-603e
branch
3 times, most recently
from
November 29, 2026 16:26
f9499d1 to
8004407
Compare
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 builds on nodejs#65364. It merges current
maininto the branch,which fixes the conflict that makes the commit queue fail, and then reworks
the change on top. The merge commit takes
main's version ofsrc/node_url_pattern.cc; commit d01ba16 carries the actual change.Because of the merge, the diff here also shows
main's changes sincef83e7df. Only the last commit is new; feel free to squash it into yours.
Changes in
src/node_url_pattern.ccParseURLPatternMatchArgsfrommaininstead of adding
ExtractInputAndBaseURL, and keeps the lexicographicmember order from 20f5b0a. In
URLPatternInit::FromJsObject, each keyis paired with the field it fills in one array, so the order can't drift
between two parallel arrays. This also drops the per-key
Utf8Valueof thekey name and the string-compare dispatch.
std::string, aUtf8Valuestays alive for the call and Ada gets a
string_viewinto it. This replacesCopyV8StringToBufferandV8StringToStdString, so there's no new helperand no simdutf include. Latin-1 and two-byte strings go through
Utf8Value's existing conversion once, not twice.isolate->GetCurrentContext()instead ofEnvironment::GetCurrent(isolate)->context(). The provider only runs insideURLPattern binding calls, where the two are the same context, and this skips
the embedder-data lookup (about 7% of
test()in profiles).exec()resultgroups. Onmain, everygroupsobject was createdwith a fresh prototype object (
Object::New(isolate, Object::New(isolate), ...)).That forced V8 to create new maps on every
exec(). It's also a WebIDLdeviation:
groupsis a record and should be an ordinary object whoseprototype is
Object.prototype. It's now a plain object filled withCreateDataProperty, so V8 reuses the same map transitions on every call.Benchmarks
Release build, Intel Xeon Gold 6548N,
benchmark/compare.js --runs 30,pinned to one core, main vs this PR:
urlpattern-execwith a match (/books/:id/chapters/:chapter)urlpattern-exec, other configurations (no match)urlpattern-test, all configurationsurlpattern-parse, init objectsurlpattern-parse, constructor stringThe existing benchmarks never exercise
exec()with a match, so this addsbenchmark/url/urlpattern-exec.js.Alternatives I measured and rejected:
groupswith the dictionary-modeObject::New(isolate, proto, names, values, n): 25–35% slower thanCreateDataProperty.DictionaryTemplateforgroups: V8 CHECK-fails on array-index names such as'0'.CreateDataProperty: only 2–5%, not worth the extra code.Note: with GCC (14 and 16), constructing a
std::optional<T>zero-fills itswhole storage, so the two
optional<Utf8Value>inURLPatternMatchArgscosta 2.5 KB memset per call; Clang doesn't do this. Even so, it measured 0–4%
faster than
main'sstd::stringcopy, so I kept it.Tests
test/parallel/test-urlpattern-fast-path.jsgains:/café) and two-byte (/😀) string inputs to the constructor,test()andexec(), with and without a base URL.groupshasObject.prototypeas itsprototype. This fails on
main.test/parallel/test-urlpattern*.jsandtest/wpt/test-urlpattern.jspass.One thing to consider: the
port: 8080 → '*'assertion pins current behaviorthat departs from WebIDL (non-string init members should be stringified).
Whoever fixes that later will have to change this test.
Not changed
exec()result still has a null prototype.exec()is split between Ada'smatch()(about 40%) and building the JS result (about 55%). The Ada sidewould be an upstream change.