[perf] Drop AstResolver from named-arg position resolution#8099
Merged
Conversation
Replace AstResolver->resolveClassMethodOrFunctionFromCall() with ReflectionResolver in RemoveMethodCallParamRector and ArgumentDefaultValueReplacer. Both rules only need the parameter *name* at a given position to map it to a named-argument position. AstResolver re-parses the callee's source file into AST just to read that name; ParameterReflection (via ParametersAcceptorSelector) already exposes it without parsing.
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.
What
RemoveMethodCallParamRectorandArgumentDefaultValueReplacerboth resolve a named-argument position by reading the parameter name at a given index of the called method/function. They did this viaAstResolver->resolveClassMethodOrFunctionFromCall(), which re-parses the callee's source file into a decorated AST — heavy — only to read$param->var->name.This swaps that for
ReflectionResolver->resolveFunctionLikeReflectionFromCall()+ParametersAcceptorSelector, reading the name straight offParameterReflection::getName(). No file re-parse.Same pattern already used by
CallLikeParamDefaultResolver.Why
AstResolver is one of the costlier analyses in the engine (parses extra files beyond the one being processed). These two sites needed only metadata reflection already holds, so the parse was pure overhead. The branch is only hit when a call uses named arguments, but removing the dependency is free correctness/perf.
Scope note
Only the two sites that need just the param name are converted. Other AstResolver callers genuinely need the AST (default-value expressions, attributes, method bodies, docblocks) and are left untouched.
Tests
Existing named-argument fixtures (
remove_named_arguments,replace_named_arguments) cover the changed branch.vendor/bin/phpunit rules-tests/Argumentsgreen (37 tests). ECS + PHPStan clean.