Skip to content

Improve performance of Prefix transformer#1665

Merged
alganet merged 1 commit into
Respect:mainfrom
alganet:prefix-perf
Feb 1, 2026
Merged

Improve performance of Prefix transformer#1665
alganet merged 1 commit into
Respect:mainfrom
alganet:prefix-perf

Conversation

@alganet

@alganet alganet commented Feb 1, 2026

Copy link
Copy Markdown
Member

The Prefix transformer had many loops that could be avoided. This change replaces them for a compiled PCRE regex, taking advantage of recent PCRE JIT capabilities introduced in PHP.

These changes offer no performance trade-offs, improving lookup for all categories of prefixes (property/key with shift, ignore list and fallback to simple rule).

The most affected is the simple rule (no prefix or no conflict with any kind of prefix rule), yielding the most gains.


Gains by scenario:

image

@alganet alganet requested a review from Copilot February 1, 2026 14:10
@codecov

codecov Bot commented Feb 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.53%. Comparing base (b352f17) to head (4ab2bdc).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #1665      +/-   ##
============================================
+ Coverage     99.29%   99.53%   +0.23%     
  Complexity      920      920              
============================================
  Files           190      190              
  Lines          2141     2148       +7     
============================================
+ Hits           2126     2138      +12     
+ Misses           15       10       -5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR optimizes the Prefix transformer by replacing multiple string-prefix loops with a single cached PCRE regex match, and adds PhpBench benchmarks to measure the impact.

Changes:

  • Reworked Respect\Validation\Transformers\Prefix to use a cached preg_match()-based parser.
  • Replaced linear skip-list checks with isset() lookups on associative arrays.
  • Added PhpBench benchmarks for common Prefix transformer scenarios.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
src/Transformers/Prefix.php Replaces prefix detection loops with a cached regex-based match and reorganizes rule lists for faster lookups.
tests/benchmark/PrefixBench.php Adds benchmark scenarios to evaluate Prefix::transform() performance across common inputs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/benchmark/PrefixBench.php Outdated
Comment thread src/Transformers/Prefix.php Outdated
Comment thread src/Transformers/Prefix.php Outdated
Comment thread src/Transformers/Prefix.php
The Prefix transformer had many loops that could be avoided. This
change replaces them for a compiled PCRE regex, taking advantage
of recent PCRE JIT capabilities introduced in PHP.

These changes offer no performance trade-offs, improving lookup
for all categories of prefixes (property/key with shift, ignore
list and fallback to simple rule).

The most affected is the simple rule (no prefix or no conflict
with any kind of prefix rule), yielding the most gains.
@alganet alganet marked this pull request as ready for review February 1, 2026 15:01
@alganet alganet merged commit 53b3bde into Respect:main Feb 1, 2026
7 checks passed
@alganet alganet deleted the prefix-perf branch February 1, 2026 22:45
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.

3 participants