Skip to content

[perf] Check method name before type inference in DBAL/ORM method call rules - #536

Merged
TomasVotruba merged 1 commit into
mainfrom
perf-doctrine-name-before-type
Oct 21, 2026
Merged

TomasVotruba merged 1 commit into
mainfrom
perf-doctrine-name-before-type

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

What

Two MethodCall rules ran isObjectType() (type inference) on the caller before comparing the method name, so the expensive type resolution ran on every method call in a file - including the overwhelming majority whose name is none of the rule's target methods and bail anyway.

  • CastDoctrineExprToStringRector - checks the target Expr method name before the QUERY_EXPR type check.
  • ReplaceFetchAllMethodCallRector - bails on any name other than fetchAll/fetchArray/fetchColumn before the two isObjectType() checks (all sub-branches only act on those names).

Pure reorder - both conditions are still ANDed, only the order flips.

Numbers

Micro bench (bench/cast_doctrine_expr_name_guard_bench.php, shipped here), refactor() over 300 non-matching method calls, 200 repeats, CPU (user+sys):

us/call
before (type-first) ~8.5
after (name-first) ~1.5

~5.7x on the common bail path. Full test suite stays green (306 tests).

@TomasVotruba
TomasVotruba merged commit 9e9d681 into main Oct 21, 2026
8 checks passed
@TomasVotruba
TomasVotruba deleted the perf-doctrine-name-before-type branch October 21, 2026 06:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant