Skip to content

perf: lazy regex - #64

Merged
qjerome merged 2 commits into
mainfrom
perf/lazy-regex
Sep 3, 2026
Merged

perf: lazy regex#64
qjerome merged 2 commits into
mainfrom
perf/lazy-regex

Conversation

@qjerome

@qjerome qjerome commented Sep 2, 2026

Copy link
Copy Markdown
Owner

No description provided.

Every regex/search-type magic rule was compiled from its pattern
string on every database deserialization, regardless of whether
that rule was ever evaluated -- 369 compilations on every wiza
invocation using the embedded database.

Wrap RegexTest's compiled Regex in a OnceLock, populated eagerly
when a rule is parsed from source (so a malformed pattern still
fails at build/parse time as before) but left empty across
deserialization, compiling lazily on first match attempt instead.
A compile failure at that point falls back to no-match rather
than propagating an error, since MagicDb::deserialize accepts
arbitrary serialized input, not just databases this build itself
produced.

Also store each pattern's capture-group count as a plain field,
computed once when the regex is actually compiled, so the static
strength/ranking computation (which runs at parse time only) no
longer needs to touch the lazy regex at all.
@qjerome qjerome changed the title Perf/lazy regex perf: lazy regex Sep 3, 2026
@qjerome
qjerome merged commit 4fd30e0 into main Sep 3, 2026
22 checks passed
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