Skip to content

perf(ext/web): optimize URLPattern ops to reduce serde overhead and GC pressure#32766

Merged
bartlomieju merged 1 commit intodenoland:mainfrom
bartlomieju:perf/urlpattern-ops
Mar 18, 2026
Merged

perf(ext/web): optimize URLPattern ops to reduce serde overhead and GC pressure#32766
bartlomieju merged 1 commit intodenoland:mainfrom
bartlomieju:perf/urlpattern-ops

Conversation

@bartlomieju
Copy link
Copy Markdown
Member

Summary

  • op_urlpattern_process_match_input: Replace #[serde] Option<(MatchInput, Inputs)> return with #[string] Option<String> + #[buffer] &mut [u32]. The 8 URL component values are concatenated into a single string with offsets written to a shared Uint32Array(9) buffer. The Inputs return (which just echoed back the caller's arguments) is eliminated entirely and reconstructed on the JS side.

  • op_urlpattern_parse: Return a lean struct that excludes the unused matcher field (containing prefix, suffix, and InnerMatcher sub-objects) from each UrlPatternComponent.

  • JS side: Components stored as indexed array instead of keyed object. Match values accessed by index. Inner loop variable shadowing fixed.

Benchmark

Benchmark Baseline Patched Speedup
test()
test(string) cached 3.96M ops/s 5.20M ops/s +31%
test(string) rotating 1k 1.90M ops/s 2.65M ops/s +39%
test(string) no match 5.40M ops/s 6.59M ops/s +22%
test(string, baseURL) 676K ops/s 942K ops/s +39%
test(init) 257K ops/s 342K ops/s +33%
test(string) complex 2.22M ops/s 3.18M ops/s +43%
exec()
exec(string) cached 1.22M ops/s 1.96M ops/s +60%
exec(string) rotating 1k 933K ops/s 1.47M ops/s +58%
exec(string) no match 2.84M ops/s 4.92M ops/s +73%
exec(string, baseURL) 481K ops/s 713K ops/s +48%
exec(init) 198K ops/s 289K ops/s +46%
exec(string) complex 1.03M ops/s 1.46M ops/s +42%
Property getters
read all 8 properties 7.81M ops/s 11.63M ops/s +49%

Test plan

  • ./x test-unit urlpattern passes
  • WPT urlpattern suite: 347 passed, 0 failed, 7 expected failures (unchanged)
  • Manual sanity test of test(), exec(), property getters, string/init/baseURL inputs

🤖 Generated with Claude Code

…C pressure

Replace serde-serialized return values in URLPattern ops with leaner
alternatives:

- `op_urlpattern_process_match_input`: return a concatenated string +
  u32 offset buffer instead of `#[serde] Option<(MatchInput, Inputs)>`.
  The `Inputs` return (which just echoed back the caller's arguments)
  is eliminated entirely and reconstructed on the JS side.

- `op_urlpattern_parse`: return a lean struct that excludes the unused
  `matcher` field (with its prefix/suffix/InnerMatcher sub-objects)
  from each UrlPatternComponent.

On the JS side, components are stored as an indexed array instead of
a keyed object, and match values are accessed by index.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@bartlomieju bartlomieju merged commit 328c8d3 into denoland:main Mar 18, 2026
112 checks passed
@bartlomieju bartlomieju deleted the perf/urlpattern-ops branch March 18, 2026 08:39
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.

2 participants