Skip to content

perf: test literal patternProperties keys with startsWith/includes - #931

Open
g4lb wants to merge 1 commit into
fastify:mainfrom
g4lb:perf-pattern-literal
Open

g4lb wants to merge 1 commit into
fastify:mainfrom
g4lb:perf-pattern-literal

Conversation

@g4lb

@g4lb g4lb commented Nov 20, 2026

Copy link
Copy Markdown

For a patternProperties key that has only letters, digits, _ and -, with an optional ^ at the start, the generated code now uses key.includes() or key.startsWith(). It does not run a regular expression for these keys. Other patterns use a regular expression, as before. The output does not change.

Benchmark (ns/op) Node 24 before Node 24 after Node 26 before Node 26 after
^n_, ^s_: 60 keys 6708 5667 (-16%) 4625 3813 (-18%)
^user_, id: 100 keys, all match 11396 10417 (-9%) 9563 8958 (-6%)
^user_, id: 50 keys, none match 2875 2167 (-25%) 2792 2167 (-22%)
^a, ^b.*c$, z: 150 keys 17230 15479 (-10%) 14896 13001 (-13%)
Regular expressions only: 100 keys 8291 8271 (0%) 7458 7542 (+1%, not significant)

I used 16 interleaved rounds and a Mann-Whitney test (Apple M2 Max, Node 24.15.0 and 26.13.1).

Checks:

  • npm test passes, with 100% coverage. A new test checks the ^ patterns and a non-literal pattern.
  • npm run lint passes.
  • Old and new outputs matched on 1.8M inputs on Node 22, 24 and 26, Bun and Deno.

This branch has not been deployed

No deployments
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