Skip to content

url: speed up URLPattern - #24

Closed
anonrig wants to merge 27 commits into
mainfrom
cursor/urlpattern-performance-603e
Closed

anonrig wants to merge 27 commits into
mainfrom
cursor/urlpattern-performance-603e

Conversation

@anonrig

@anonrig anonrig commented Aug 18, 2026 •

Copy link
Copy Markdown
Owner

This speeds up WHATWG URLPattern constructor, test(), and exec() without changing observable behavior.

Independent of the new URL() parse PR (nodejs#65361) and the URLSearchParams PR (nodejs#65363).

What changed

C++ only (src/node_url_pattern.cc):

  • String input: copy one-byte ASCII V8 strings with ValueView + memcpy into a stack buffer and pass a string_view into Ada. Drop the extra std::string copy that BufferValue/Utf8Value::ToString() used to make. Non-ASCII still goes through Utf8Value.
  • Object init: look up the nine interned component keys and assign fields by index. Skip UTF-8-converting each key name and the string-compare chain. Non-string members are still ignored.
  • Regexp provider: convert pattern/input strings with ToV8Value and use isolate->GetCurrentContext() instead of Environment::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. ValueView is destroyed before any V8 heap allocation.

Tests

  • test/parallel/test-urlpattern.js, test-urlpattern-types.js, test-urlpattern-invalidthis.js, and test-urlpattern-fast-path.js all pass
  • WPT test/wpt/test-urlpattern.js: 743 passed, 0 unexpected failures

Review follow-up

  • Dropped the local NewStringFromUtf8View helper in favor of ToV8Value
  • CopyV8StringToBuffer takes a pointer, matching project convention for mutating arguments
  • Author and Signed-off-by are Yagiz Nizipli (human DCO)

Assisted-by: Cursor

Open in Web Open in Cursor 

@anonrig
anonrig marked this pull request as ready for review August 18, 2026 01:50
@cursor
cursor Bot force-pushed the cursor/urlpattern-performance-603e branch 6 times, most recently from ed512d0 to 1ba9273 Compare August 18, 2026 18:43
manusingh090 and others added 23 commits November 27, 2026 04:42
CallIntoModule() reset last_exception only after handle_exception()
returned. When handle_exception() reports the exception through
'uncaughtException', the listener runs while the exception is still
pending, so calling back into the module from it saw the same
exception again: an addon function failed with napi_pending_exception
and rethrew it, and a finalizer run by gc() in an experimental module
reported it a second time, which aborted the process with
"Re-entrant uncaught exception detected".

Take the exception out of last_exception before handling it.

Fixes: nodejs#67421
Assisted-by: a coding agent
Signed-off-by: Manjeet Singh <024manjeetsingh@gmail.com>
PR-URL: nodejs#67448
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Signed-off-by: LiviaMedeiros <livia@cirno.name>
PR-URL: nodejs#67582
Refs: https://github.com/nodejs/node/blob/HEAD/doc/contributing/erm-guidelines.md#debuggability-of-disposer-methods
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Signed-off-by: LiviaMedeiros <livia@cirno.name>
PR-URL: nodejs#67582
Refs: https://github.com/nodejs/node/blob/HEAD/doc/contributing/erm-guidelines.md#debuggability-of-disposer-methods
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Signed-off-by: ishabi <ilyasshabi94@gmail.com>
PR-URL: nodejs#67732
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
Reviewed-By: James M Snell <jasnell@gmail.com>
Co-authored-by: Brian Muenzenmeyer <brian.muenzenmeyer@gmail.com>
Signed-off-by: avivkeller <me@aviv.sh>
PR-URL: nodejs#66713
Reviewed-By: Claudio Wunder <cwunder@gnome.org>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Signed-off-by: Mohamed Sayed <k@3zrv.com>
Signed-off-by: RafaelGSS <rafael.nunu@hotmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
PR-URL: nodejs#67112
Add `request.signal` to `Http2ServerRequest`, matching
`message.signal` in HTTP/1. The signal follows the stream, not the
socket: it is aborted when the stream closes before the response has
been sent completely.

Refs: nodejs#62541
Refs: nodejs#64392
Signed-off-by: inoway46 <inoueyuya416@gmail.com>
Assisted-by: Claude Code
PR-URL: nodejs#67774
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
`expandedSQL`, `sourceSQL`, column names and the `sqlite.db.query`
trace callback passed SQL text to `String::NewFromUtf8()` without a
length, and V8 aborted on text longer than `String::kMaxLength`.
Pass the length instead. The getters and column names now throw
`ERR_STRING_TOO_LONG`, and the trace callback skips the event so the
statement still runs.

Co-authored-by: lazerg <lazerg2@gmail.com>
Signed-off-by: Christian Aurich Zanettini Martins <christian.aurichzm@gmail.com>
PR-URL: nodejs#67768
Fixes: nodejs#66487
Refs: nodejs#66498
Reviewed-By: Guilherme Araújo <arauujogui@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Signed-off-by: Chengzhong Wu <cwu631@bloomberg.net>
PR-URL: nodejs#67778
Fixes: nodejs#67267
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: LiviaMedeiros <livia@cirno.name>
Reviewed-By: Efe Karasakal <hi@efe.dev>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
When a server responds before it has read the whole request body, the
client stops forwarding the socket's 'drain' to the request as soon as
the response is complete. A writer that honors backpressure, such as a
stream piped into the request, then never receives 'drain', never calls
end(), and the socket keeps the process alive.

Keep the 'drain' listener until the request has ended and remove it in
responseKeepAlive() when the socket is released back to the pool.

Fixes: nodejs#67763
Signed-off-by: Matteo Collina <matteo.collina@gmail.com>
PR-URL: nodejs#67780
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Signed-off-by: Tim Perry <pimterry@gmail.com>
PR-URL: nodejs#67781
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Signed-off-by: Tim Perry <pimterry@gmail.com>
PR-URL: nodejs#67781
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Signed-off-by: Tim Perry <pimterry@gmail.com>
PR-URL: nodejs#67781
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Signed-off-by: Filip Skokan <panva.ip@gmail.com>
PR-URL: nodejs#67781
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
The loong64, ppc64, riscv64, and s390x fast trampoline emitters each
duplicated the signature validation, executable memory allocation,
cache flush and mprotect sequence, trampoline release, and (for the
fixed-width 32-bit ISAs) the instruction word emitters. Move them into
a shared scalar_trampoline.h header so each platform file only
contains its architecture-specific instruction encoding.

Assisted-by: Claude
Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: nodejs#67496
Reviewed-By: Vladimir Morozov <vmorozov@microsoft.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
The System V and Win64 halves of the x64 fast trampoline emitter each
defined identical copies of the register constants, the byte/word
emitters, the REX/ModRM, mov, call, jmp, stack adjustment, and ret
encoders, and the narrow return normalization helpers. Define them
once ahead of the ABI-specific code.

Assisted-by: Claude
Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: nodejs#67496
Reviewed-By: Vladimir Morozov <vmorozov@microsoft.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
napi_create_error(), napi_create_type_error(), napi_create_range_error()
and node_api_create_syntax_error() differed only in the v8::Exception
factory used, as did the corresponding napi_throw_*() functions. Move
the bodies into internal CreateError() and ThrowError() helpers that
take the factory. The exported functions and their signatures are
unchanged, so there is no ABI impact.

Assisted-by: Claude
Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: nodejs#67496
Reviewed-By: Vladimir Morozov <vmorozov@microsoft.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
DynamicLibrary::UnregisterCallback(), RefCallback(), and UnrefCallback()
each duplicated the closed-library check, pointer argument validation,
and callback map lookup. Move them into a shared FindCallback() helper.

Assisted-by: Claude
Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: nodejs#67496
Reviewed-By: Vladimir Morozov <vmorozov@microsoft.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
The network and DOM storage agents repeated the same pattern dozens of
times: read a property with an ObjectGet*() helper and throw a
"Missing <name> in event" TypeError if it was absent. Add
ObjectGetRequired() overloads that combine the two, move the duplicated
ThrowEventError() into inspector_object_utils, and use them throughout
both agents. Error messages are unchanged.

Assisted-by: Claude
Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: nodejs#67496
Reviewed-By: Vladimir Morozov <vmorozov@microsoft.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
The SetMethod(), SetFastMethod(), SetMethodNoSideEffect(),
SetProtoMethod(), SetInstanceMethod(), and SetProto*Dispose() variants
each repeated the same function template construction, internalized
name string creation, and installation code, differing only in side
effect type, receiver signature, and target. Factor that into a small
set of internal helpers.

Assisted-by: Claude
Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: nodejs#67496
Reviewed-By: Vladimir Morozov <vmorozov@microsoft.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
When the creation context of the import.meta object has no associated
Realm, the getter threw ERR_INVALID_INVOCATION but then fell through
and dereferenced the null Realm. Return after throwing, as the other
error paths in the getter already do.

Assisted-by: Claude
Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: nodejs#67496
Reviewed-By: Vladimir Morozov <vmorozov@microsoft.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
ImportMetaResolveLazyGetter() and PathHelpersLazyGetter() duplicated
the code that retrieves the creation context from the holder object.
Move it into a shared GetHolderCreationContext() helper.

Assisted-by: Claude
Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: nodejs#67496
Reviewed-By: Vladimir Morozov <vmorozov@microsoft.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
All three callers of report::WriteNodeReport() computed the
excludeNetwork and excludeEnv options the same way, falling back to the
process-wide defaults when there is no Environment. Do that once inside
WriteNodeReport() instead.

Assisted-by: Claude
Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: nodejs#67496
Reviewed-By: Vladimir Morozov <vmorozov@microsoft.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
jasnell and others added 3 commits November 27, 2026 16:26
FastHas() duplicated the scope parsing in FastHasResource(). Move the
shared logic into FastHasImpl(), with FastHas() passing an empty
resource.

Assisted-by: Claude
Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: nodejs#67496
Reviewed-By: Vladimir Morozov <vmorozov@microsoft.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
StreamBase::WriteBuffer() and WriteString() duplicated the code that
creates a request object when needed and attaches the handle being sent
over an IPC pipe. Move it into a shared PrepareSendHandle() helper.

Assisted-by: Claude
Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: nodejs#67496
Reviewed-By: Vladimir Morozov <vmorozov@microsoft.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
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
@cursor
cursor Bot force-pushed the cursor/urlpattern-performance-603e branch from 1ba9273 to 5e3d9a2 Compare November 28, 2026 01:47
The fast path looked up component names in component order, so
constructing a URLPattern from an object invoked getters as
protocol, username, password, and so on. WebIDL requires
lexicographical order, which test/parallel/test-urlpattern.js
checks. That test failed on every platform. Also put the baseURL
conversion on one line so clang-format is clean.

Signed-off-by: Yagiz Nizipli <yagiz@nizipli.com>
Assisted-by: Cursor
Co-authored-by: Yagiz Nizipli <anonrig@users.noreply.github.com>
@anonrig anonrig closed this Nov 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.