Skip to content

Perf: Cut repeated per-method lookups in the initializer, narrowing and covers hooks - #291

Merged
alies-dev merged 3 commits into
psalm:masterfrom
alies-dev:perf-hook-loops
Nov 24, 2026
Merged

alies-dev merged 3 commits into
psalm:masterfrom
alies-dev:perf-hook-loops

Conversation

@alies-dev

@alies-dev alies-dev commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Three hooks repeated lookups per method: the visit hook found the @before/#[Before] methods of a class with one linear ClassLike::getMethod() per method (quadratic in the width of the class), DataProviderNarrowingHandler scanned every inherited method to find the analysed test, and hasInitializers() and (on PHPUnit 11) the docblock covers check loaded the declaring class storage for every inherited method. Reported issues are unchanged.

Generated fixtures, PHPUnit 13 (11 for the covers check), --threads=1 --debug-performance, median of 3:

Hook Fixture Before After
TestCaseHandler AfterClassLikeVisit 10 classes × 480 methods 48 ms 4 ms
TestCaseHandler AfterClassLikeVisit 60 classes × 128 methods 37 ms 11 ms
DataProviderNarrowingHandler BeforeStatementAnalysis 480 tests after 120 helpers each 27 ms 21 ms
CoversTargetHandler AfterClassLikeAnalysis 140 tests × 360 inherited methods 13 ms 6 ms
TestCaseHandler AfterCodebasePopulated same 10 ms 4 ms

Follow-up of #289.

getBeforeMethods() makes one pass over the methods of the class instead of a linear ClassLike::getMethod() per method, and hasInitializers() reads the before methods of each declaring class once.
@alies-dev alies-dev self-assigned this Nov 24, 2026
@alies-dev alies-dev changed the title Cut repeated per-method lookups in the initializer, narrowing and covers hooks Perf: Cut repeated per-method lookups in the initializer, narrowing and covers hooks Nov 24, 2026
@alies-dev alies-dev added the release:internal The PR will be included in 'Internal changes' section of the release notes label Nov 24, 2026
@alies-dev
alies-dev merged commit 9971f92 into psalm:master Nov 24, 2026
8 checks passed
@alies-dev
alies-dev deleted the perf-hook-loops branch November 24, 2026 11:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release:internal The PR will be included in 'Internal changes' section of the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant