Skip to content

refactor(core): cache compiled wildcard RegExp per pattern - #63452

Closed
delaysystem wants to merge 2 commits into
anomalyco:devfrom
delaysystem:opt/wildcard-regex-cache
Closed

delaysystem wants to merge 2 commits into
anomalyco:devfrom
delaysystem:opt/wildcard-regex-cache

Conversation

@delaysystem

Copy link
Copy Markdown

Issue for this PR

N/A — small performance refactor, no behavior change.

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Wildcard.match recompiled its RegExp from the pattern on every call, and compiling dominates the cost of a match. Since callers reuse a small set of patterns, this caches the compiled expression per pattern in a capped (1000-entry, FIFO) map, with the platform flags hoisted out of the hot path. Matching semantics are unchanged.

How did you verify your code works?

Ran the focused suite in packages/core:

bun test test/util-wildcard.test.ts
6 pass, 0 fail, 34 expect() calls

Includes the new tests for metacharacter escaping, trailing * handling, and repeat-call consistency.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

The highlights query floated on main while the wasm parser is pinned to 0.7.1. The main query references nodes the old grammar does not know, so it fails to compile and swift renders plain. Pin the query to 0.7.1 and assert the query URL tracks the pinned wasm version.
Cache compiled expressions in a capped (1000-entry FIFO) map keyed by raw pattern, with flags hoisted. Adds tests.
@opencodejr opencodejr Bot closed this Nov 12, 2026
@opencodejr

opencodejr Bot commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Thanks for looking into the Wildcard.match hot path! I think this duplicates #55322, which already caches the compiled RegExp per pattern in a size-capped map and adds tests for the same matching behaviour.

If you think something is missing there, such as a case your tests cover, please review or comment on #55322.

Also, this branch includes the Swift highlights pin commit (b8e5960e5), which you're already proposing separately in #63165. It's best to keep that one there.

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