Repository navigation
[Performance] Hoist loop-invariant resolve+continue guards above foreach - #8761
Merged
Merged
Conversation
In StaticCallToNewRector and AddArrowFunctionParamArrayWhereDimFetchRector a value resolved from a loop-invariant node was fetched inside a foreach, then a continue guard repeated it every iteration. Hoist the resolve above the loop and bail once.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two rules resolved a value from a loop-invariant node inside a foreach, then guarded it with a
continue. Since the node does not change per iteration, the resolve returns the same value every pass and the guard fires identically - so it belongs above the loop, bailing once.StaticCallToNewRector-$class = $this->getName($node->class)+ nullcontinuedepended only on$node->class; hoisted above the loop with a singlereturn null.AddArrowFunctionParamArrayWhereDimFetchRector-$this->getType($closureItems)and its object-array guard were run per closure param, though$closureItemsis fixed for the whole param loop; resolved once before the loop.Found by an AST scan for the pattern: inside a foreach, an assignment from a method call whose arguments and receiver are all loop-invariant, immediately followed by
if (...) { continue; }testing the assigned variable.