Skip to content

Reduce calls to Scope->getType(). Cheap checks first. #2071

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 9, 2022

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Dec 9, 2022

 php -v
PHP 8.1.13 (cli) (built: Nov 24 2022 15:58:42) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.13, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.13, Copyright (c), by Zend Technologies
    with blackfire v1.81.0~mac-x64-non_zts81, https://blackfire.io, by Blackfire

blackfire run php bin/phpstan -vvv --debug

grafik

@ondrejmirtes
Copy link
Member

Oh yeah 😊 Thank you 😊 If you find more of these that'd be great!

@ondrejmirtes ondrejmirtes merged commit 335daac into phpstan:1.9.x Dec 9, 2022
@staabm staabm deleted the gettype-calls branch December 9, 2022 20:22
@voku
Copy link
Contributor

voku commented Dec 9, 2022

I think the Php Inspections (EA Extended) plugin for PhpStorm had a inspection for non optional conditions. Maybe it can find some more stuff? 🤔

@staabm
Copy link
Contributor Author

staabm commented Dec 10, 2022

@voku I don't have this plugin. if you find something useful, even if its just a bottleneck without a idea to optimize it, feel free to report. someone will help you :)

@staabm
Copy link
Contributor Author

staabm commented Dec 10, 2022

If you find more of these that'd be great!

@ondrejmirtes I thought about whether we should have a few performance oriented rules.

somethink like ExpensiveCallsInBooleanAndRule which you would give a list of method references, known to be expensive, and the rule would report if these method calls happen in a && condition, but could be re-ordered to be called later... (like we saw in this PR)

another rule could be ExpensivePureCallInLoop which would report when a pure-call of a expensive method (e.g. TypeCombinator::union) happens within a loop, but does not depend on variables which dependend on the loop-scope.
(and the returned type is not relevant for the loop-scope).

wdty?

@ondrejmirtes
Copy link
Member

These rules are really hard to do. Maybe once we have the contro flow graph, it will become easier.

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.

None yet

3 participants