-
Notifications
You must be signed in to change notification settings - Fork 667
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
Make callbacks marked as static #6695
Conversation
Is there a performance benefit from this? |
Don't think so (hopefully, I'm wrong :)). It's more about memory leak prevention. Analyzing Psalm codebase shows about 0.5Mb of memory save. So it's more about a proper usage of callbacks rather than optimization. |
@SCIF |
I believe PHPInspectionsEA for PHPStorm has a similar feature |
I've done it using regex replace :) I didn't try to find a special tool to do that |
I thought PHPInspectionsEA too :)
Ok, I see. |
Afair php-cs-fixer can do it |
If you can rebase this and @weirdan is okay with it, I'm up for merging this |
Will do today. Thanks! |
Sorry, I'm still in process of doing that. I'm fixing the conflicts because of replacing |
Guys, I just noticed there are A LOT of
I was quite amazed to see that |
All green apart from CS and labels. Will fix cs soon. Make this PR ready to review. Gonna squash commits prior merging, so let me know when it will look fine for everybody. |
src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentsAnalyzer.php
Outdated
Show resolved
Hide resolved
src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArrayFunctionArgumentsAnalyzer.php
Outdated
Show resolved
Hide resolved
@@ -445,7 +445,7 @@ private static function handleNamedCall( | |||
|
|||
$mixin_candidates_no_generic = array_filter( | |||
$mixin_candidates, | |||
fn($check): bool => !($check instanceof TGenericObject) | |||
static fn($check): bool => !($check instanceof TGenericObject) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type is known here
End-to-end failures looks valid to me:
|
They are, but they doesn't come from your changes, we have to baseline them. @weirdan would you mind? I think we have some on 4.x as weel as on master |
327d408
to
67c329a
Compare
Squashed the commits in the branch. Fixed all the comments. I spoofed Based on my app, all those changes speed it up 0.5-1s (4 threads, ~55 second in total), but it's really hard to evaluate the precise number as results fluctuate a lot. So I believe there is some speedup but it's actually not such noticeable. |
0c83c16
to
ec35b06
Compare
src/Psalm/Internal/Analyzer/Statements/Block/IfConditionalAnalyzer.php
Outdated
Show resolved
Hide resolved
src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/AndAnalyzer.php
Outdated
Show resolved
Hide resolved
src/Psalm/Internal/Analyzer/Statements/Block/IfElseAnalyzer.php.orig
Outdated
Show resolved
Hide resolved
src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeNodeScanner.php.orig
Outdated
Show resolved
Hide resolved
5be3195
to
6baab4e
Compare
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to debug errors:
ERROR: Trace - src/Psalm/Internal/Algebra.php:48:49 - $anded_types: non-empty-list<non-empty-list<Psalm\Storage\Assertion>> (see https://psalm.dev/224)
/** @psalm-trace $anded_types */;
ERROR: Trace - src/Psalm/Internal/Algebra.php:49:53 - $new_anded_types: list<Psalm\Storage\Assertion> (see https://psalm.dev/224)
/** @psalm-trace $new_anded_types */;
It looks like continue 2;
is not properly handled by psalm here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd have to take a closer look but I don't have much time these days. Can you add an assert($new_anded_types !== []);
? I think this should do the trick :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, that helps. But that's excessive code (a performance waster) intended just to calm psalm. Tbh, adding this to baseline would be a bit better. I propose to wait a few days other suggestions :)
@@ -121,7 +121,7 @@ public function __construct( | |||
$this->protocolReader = $reader; | |||
$this->protocolReader->on( | |||
'close', | |||
function (): void { | |||
static function (): void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This must fail. Probably the LanguageServer is not covered with tests.
@@ -56,7 +56,7 @@ public function __construct($input) | |||
/** | |||
* @return Generator<int, Promise<?string>, ?string, void> | |||
*/ | |||
function () use ($input): Generator { | |||
static function () use ($input): Generator { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This must fail as well.
6baab4e
to
3619194
Compare
|
I squashed commits, double checked my changes, reverted too dangerous changes. Please give me a hand to overcome psalm errors I highlighted above. Would highly appreciate if you would review/help to conclude this PR as it's really time consuming (I know this is unwanted refactoring and you could oppose it, then I will considering closing the PR). |
I fully intend to merge this :) I haven't been able to spend a lot of time on Psalm these days, sorry if I don't always respond in time |
No need to be sorry. You are one of the most active contributors and in general Psalm has very good response time which a lot of OpenSource projects can dream of. |
Don't want to bother by mentioning core devs, so just calling for the advice how to overcome the issue above. Gonna to add asserts over the weekend if no better solutions will be suggestion. |
3619194
to
b4fdc3e
Compare
I have merged the PR with the latest master. The issues coming from it. |
I'm ready to merge if you are :) |
I did my best and double checked the logic of all changes. The places which I suspected, I reworked in a separate file and compared with my PR's one. That strategy gave me results I reflected in comments above. Looks fine to me now :) A review from @weirdan is locking the merge apparently. |
nah, that's okay :) Thanks! |
Some callbacks converted to callables