-
-
Notifications
You must be signed in to change notification settings - Fork 932
-
loops are the obvious performance bottlenecks we see in applications every day.
sometimes loops are slower then necessary, because method/function-calls which do not depend on a variable, which changes with iterations is used within the loop, but could just be moved outside the loop.
pseudo-code:
$x = 3; foreach($iterator as $value) { $this->somePureMethod($x); // more loop body }
since the method is pure, invoking it on every iteration is unnecessary and the code could be rewritten to
$x = 3; this->somePureMethod($x); foreach($iterator as $value) { // loop body }
should phpstan error when pure functions/methods are used within a loop, but do not depend on its iterations?
another benefit of moving code outside a loop, is more readable code
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment
-
It's currently hard to track this and not report code that's valid but in the future this should be possible.
Beta Was this translation helpful? Give feedback.
All reactions
-
❤️ 1