Skip to content

url: speed up URLPattern - #24

Open
anonrig wants to merge 1 commit into
mainfrom
cursor/urlpattern-performance-603e
Open

url: speed up URLPattern#24
anonrig wants to merge 1 commit 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
  • Removed Signed-off-by from the commit (AI agents cannot attest DCO)
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 2 times, most recently from 52a2a71 to a2e81de Compare August 18, 2026 12:49
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>
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
@cursor
cursor Bot force-pushed the cursor/urlpattern-performance-603e branch from a2e81de to b1e8b1d Compare August 18, 2026 12:50
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.

1 participant