Skip to content

Use Perex literal-prefix execution without DFA storage - #12792

Merged
proggeramlug merged 3 commits into
mainfrom
px/perex-anchored-literal
Oct 18, 2026
Merged

proggeramlug merged 3 commits into
mainfrom
px/perex-anchored-literal

Conversation

@proggeramlug

@proggeramlug proggeramlug commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Start-anchored literal programs such as /^--/ now compare the original subject with immutable Perex program data before consulting the DFA. Prefix programs carry no DFA cache and need no evaluator scratch. Literal evaluation continues to create a fresh RegExp object with isolated lastIndex around shared matcher data.

Uses published perex 0.1.14, released through Perex #6. Cargo.lock pins the verified registry artifact; no path or git override remains. The documented one-time publish-age resolution leaves the global seven-day policy unchanged.

Both arms were built and measured on qb7 from common parent bc00158c1, using instructions:u n=3 medians, with exact Node output parity:

Witness Base instructions Head instructions Delta .text delta
commander 2,868,681,289 2,853,650,581 -0.5240% +2,304 B
qs_parse 9,001,137,263 9,001,350,246 +0.0024% +1,920 B
marked 397,143,828 397,835,410 +0.1741% +1,520 B
effect (noopt) 6,056,051,462 6,056,137,612 +0.0014% +3,072 B
1M anchored replacements 3,700,610,012 3,568,976,865 -3.5571% +1,520 B

Commander’s DFA sample share falls 2.24% → 1.34%. The small marked cost is in prefix-descriptor admission (program_bounds / perex::dfa::find); qs_parse and effect are effectively flat. Paired perrymaster wall/RSS samples are recorded with host load; short-run wall timings overlap substantially under shared-host load.

Validation: final-head pmcheck passed: unified registry build, sidecars, zod/tsc smokes and 92 instrumented regex unit tests (single-threaded). Nine final regex gap files match both Node 26.5.1 and 26.8.1; Windows runtime+stdlib cargo-xwin checks pass. Perex fmt/check/clippy, 460 debug/release unit/doc tests, engine differential harness (zero unreviewed differences), and package verification pass. Local related runtime coverage also passed 108 tests. Symbol-preserving profiling binaries have byte-identical .text.

Fresh literal identities, lastIndex mutation, sticky/global flags, multiline anchors, Unicode/surrogate starts, templates, callbacks and overridden exec are covered. Current main already shares literal matcher data. Reuse owns no per-operation buffer; source/disassembly shows allocation only on cold handle-stack capacity growth.

Summary by CodeRabbit

  • Performance
    • Anchored literal regular expressions now use a faster matching path, including for Unicode patterns and different starting positions.
    • This optimization preserves expected behavior for replacements, captures, flags, and each regular expression’s independent lastIndex state.

@coderabbitai

coderabbitai Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 815b87a0-2229-441c-ba0e-1b27213dd73a
📥 Commits

Reviewing files that changed from the base of the PR and between 8fba1e2 and d4f60e8.

⛔ Files ignored due to path filters: 1
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing: 6
  • Cargo.toml
  • changelog.d/12792-perex-anchored-literal.md
  • crates/perry-runtime/src/regex/perex_owner.rs
  • crates/perry-runtime/src/regex/perex_runtime.rs
  • crates/perry-runtime/src/regex/perex_runtime/dfa_tests.rs
  • test-files/test_gap_regexp_anchored_literal_prefix.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

📝 Walkthrough

The Perex dependency is updated to 0.1.14. The runtime tries exact literal-prefix execution before the lazy DFA. Cache allocation and tests are updated for anchored literal patterns and their RegExp behavior.

Changes: Anchored literal execution

Layer / File(s) Summary
Perex version and cache allocation
Cargo.toml, crates/perry-runtime/src/regex/perex_owner.rs
The workspace updates Perex from 0.1.13 to 0.1.14. Programs with a zero-word DFA minimum now receive zero DFA cache words.
Prefix execution and regression coverage
crates/perry-runtime/src/regex/perex_runtime.rs, crates/perry-runtime/src/regex/perex_runtime/dfa_tests.rs, test-files/test_gap_regexp_anchored_literal_prefix.ts, changelog.d/12792-perex-anchored-literal.md
program_bounds tries the literal-prefix executor before the DFA and maps prefix results to bounds without capture groups. Tests check prefix results, DFA and evaluator counters, and RegExp replacement behavior. The changelog records the executor and per-evaluation RegExp state.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Refactor

Sequence Diagram(s)

sequenceDiagram
  participant search
  participant program_bounds
  participant literalPrefixExecutor
  participant lazyDFA
  search->>program_bounds: Request bounds
  program_bounds->>literalPrefixExecutor: Search program prefix from start
  alt Prefix available
    literalPrefixExecutor-->>program_bounds: Return match or no-match bounds
  else No prefix available
    program_bounds->>lazyDFA: Evaluate program
    lazyDFA-->>program_bounds: Return DFA result
  end
  program_bounds-->>search: Return bounds
Loading
Merge Risk: ⚪ Minimal · up to d4f60

This change adds a fast path for start-anchored literal regexes and updates the Perex dependency. No concrete merge-blocking risk was identified in the supplied context, and the new tests cover the main RegExp behaviors.

Pre-merge checks: Passed 5
Check name Status Explanation
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 4 files. (2 skipped: 2 …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Title check Passed The title clearly and concisely identifies the main change: using Perex literal-prefix execution without DFA storage.
Description check Passed The description provides a detailed summary of the implementation, performance results, and validation. It covers the substantive Summary, Changes, and Test plan content, but it does not use the templ…
Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 4 files. (2 skipped: 2 unsupported.)

Full details: Description check

Explanation

The description provides a detailed summary of the implementation, performance results, and validation. It covers the substantive Summary, Changes, and Test plan content, but it does not use the template headings or explicitly provide a Related issue, Screenshots / output, or Checklist section.

✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@proggeramlug
proggeramlug force-pushed the px/perex-anchored-literal branch from 2a31c25 to d4f60e8 Compare October 18, 2026 10:45
@proggeramlug
proggeramlug marked this pull request as ready for review October 18, 2026 11:33
@proggeramlug
proggeramlug merged commit 62c49c3 into main Oct 18, 2026
105 of 131 checks passed
@proggeramlug
proggeramlug deleted the px/perex-anchored-literal branch October 18, 2026 11:37
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