Skip to content

Faster DuplicateFunctionDeclarationRule#6039

Merged
staabm merged 3 commits into
phpstan:2.2.xfrom
staabm:funcs
Jul 11, 2026
Merged

Faster DuplicateFunctionDeclarationRule#6039
staabm merged 3 commits into
phpstan:2.2.xfrom
staabm:funcs

Conversation

@staabm

@staabm staabm commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

similar to #6038

the improvement is rather small because phpstan-src contains only few global functions.
in codebases with more functions it should safe even more. we also do this for consistency with DuplicateClassDeclarationRule


before the PR:

➜  phpstan-src git:(2.2.x) hyperfine 'php -d memory_limit=450M bin/phpstan analyze -v --debug src/Testing' -i
Benchmark 1: php -d memory_limit=450M bin/phpstan analyze -v --debug src/Testing
  Time (mean ± σ):      3.221 s ±  0.016 s    [User: 2.844 s, System: 0.372 s]
  Range (min … max):    3.201 s …  3.254 s    10 runs

after the PR:

➜  phpstan-src git:(funcs) hyperfine 'php -d memory_limit=450M bin/phpstan analyze -v --debug src/Testing' -i
Benchmark 1: php -d memory_limit=450M bin/phpstan analyze -v --debug src/Testing
  Time (mean ± σ):      3.202 s ±  0.007 s    [User: 2.837 s, System: 0.361 s]
  Range (min … max):    3.195 s …  3.218 s    10 runs

inspired by 11aebc1 which also memoizes allConstants. this method has not a single caller in one of the phpstan/* repos, therefore we don't tackle it

@staabm staabm marked this pull request as ready for review July 11, 2026 16:18
@phpstan-bot

Copy link
Copy Markdown
Collaborator

This pull request has been marked as ready for review.

@staabm staabm requested a review from VincentLanglet July 11, 2026 16:18
@staabm staabm merged commit e58fab6 into phpstan:2.2.x Jul 11, 2026
668 of 670 checks passed
@staabm staabm deleted the funcs branch July 11, 2026 20:22
staabm referenced this pull request Jul 11, 2026
Each call swept every source locator, re-reading and re-parsing all stub
files evicted from the parser cache. DuplicateClassDeclarationRule and
DuplicateFunctionDeclarationRule call these for every class/function
node during stub validation, causing ~4900 redundant file reads per
process on phpstan-src self-analysis.
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