Skip to content

[perf] Check method name before type inference in PHPUnit test-case call guard - #807

Merged
TomasVotruba merged 1 commit into
mainfrom
perf-phpunit-testcase-call-guard
Oct 21, 2026
Merged

TomasVotruba merged 1 commit into
mainfrom
perf-phpunit-testcase-call-guard

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

What

TestsNodeAnalyzer::isPHPUnitMethodCallNames() is the gate used by ~25 assert rules (every rule subscribed to MethodCall/StaticCall). It ran NodeTypeResolver::getType() on the caller first and only then compared the method name, so the expensive type inference ran on every method call in a file - including the overwhelming majority that are not assert* calls and bail on the name anyway.

This reorders the guard to compare the cheap method name first; a non-matching call now bails before any getType().

Numbers

Micro bench (bench/phpunit_testcase_call_guard_bench.php, shipped with this PR), AssertInstanceOfComparisonRector::refactor() driven over 300 non-assert method calls, 200 repeats, CPU time (user+sys):

us/call
before (type-first) ~15.0
after (name-first) ~8.0

~1.8x on the common bail path. Behaviour is unchanged - both conditions are still ANDed, only the order flips.

Full test suite stays green (685 tests).

@TomasVotruba
TomasVotruba merged commit 0527bb1 into main Oct 21, 2026
8 checks passed
@TomasVotruba
TomasVotruba deleted the perf-phpunit-testcase-call-guard branch October 21, 2026 06:24
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