Skip to content

Perf: Skip the methods without PHPUnit metadata in the per-class method loops - #290

Merged
alies-dev merged 3 commits into
psalm:masterfrom
alies-dev:289-skip-methods-without-phpunit-metadata
Nov 24, 2026
Merged

alies-dev merged 3 commits into
psalm:masterfrom
alies-dev:289-skip-methods-without-phpunit-metadata

Conversation

@alies-dev

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

Copy link
Copy Markdown
Contributor

Psalm spent time proportional to test classes × inherited methods in the AfterClassLikeAnalysis hooks of TestCaseHandler and DocblockMetadataHandler, recomputing the same trait and parent method checks for every test class. The visit hook now records the methods with an attribute or a docblock that may hold a PHPUnit 11 tag, and both loops skip the other methods unless the test case names them test*. Reported issues are unchanged.

400 generated test classes on a base test case with 16 traits of 22 methods, PHPUnit 13, --threads=1 --debug-performance, median of 3:

Hook Before After
TestCaseHandler AfterClassLikeAnalysis 809 ms 71 ms
DocblockMetadataHandler AfterClassLikeAnalysis 485 ms 19 ms
TestCaseHandler AfterClassLikeVisit 22 ms 18 ms

Fixes #289

…#289

Trait aliases with test names, #[Test] and @test on methods with other names in a
trait and in a parent (also when only the subclass file is analysed), a hook tag and a
malformed tag on trait methods, and every docblock tag PHPUnit 11 reads.
psalm#289

afterClassLikeVisit() records the methods a class-like declares with an attribute or
a docblock that may hold a tag PHPUnit 11 reads, next to the before methods. Both
AfterClassLikeAnalysis loops over declaring_method_ids skip the other methods, unless the
test case names them test*: PHPUnit reads nothing from them. DocblockSpecials parses
only the docblocks that pass the same check.
@alies-dev alies-dev self-assigned this Nov 24, 2026


Storage cached by an older version of the plugin has no with_metadata key. Psalm keeps that cache when only the plugin changes and the project's composer.lock does not (a global install), so an absent key means unknown, not empty.
@alies-dev
alies-dev marked this pull request as ready for review November 24, 2026 00:55
@alies-dev alies-dev changed the title Skip the methods without PHPUnit metadata in the per-class method loops Perf: Skip the methods without PHPUnit metadata in the per-class method loops Nov 24, 2026
@alies-dev
alies-dev merged commit fc4fc0b into psalm:master Nov 24, 2026
8 checks passed
@alies-dev
alies-dev deleted the 289-skip-methods-without-phpunit-metadata branch November 24, 2026 09:15
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.

Per-test-class loops over declaring_method_ids repeat work for every inherited and trait method (about 3 % of analysis time in a large Laravel app)

1 participant