Skip to content

Remove runtime autoloading from NodeTypeResolver#3627

Merged
samsonasik merged 2 commits intorectorphp:mainfrom
staabm:simple
Apr 20, 2023
Merged

Remove runtime autoloading from NodeTypeResolver#3627
samsonasik merged 2 commits intorectorphp:mainfrom
staabm:simple

Conversation

@staabm
Copy link
Copy Markdown
Contributor

@staabm staabm commented Apr 17, 2023

see #3502 (comment) for background

}

$classReflection = $this->reflectionProvider->getClass($resolvedObjectType->getClassName());
if (! isset($this->traitExistsCache[$classReflection->getName()])) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think since we already checked with hasClass that $resolvedObjectType->getClassName() exists, we only need to check with isTrait() whether its a trait.

in my thinking it should be equivalent to what this cache was doing before.

@keulinho could you verify this has the same perf characteristics for your use case, as measured in #3501 ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change in general looks good to me and the solution way more elegant that mine 🙈

actually i've paused trying to get rector running smoothly with our codebase for now, i will get back when i have the time to look at it again

@staabm
Copy link
Copy Markdown
Contributor Author

staabm commented Apr 17, 2023

I think the failling job shows us one of the side-effects I mentioned in #3502 (comment).

the test-case worked before this PR because it autoloaded the trait at runtime, which doesn't look right to me.

@staabm staabm marked this pull request as ready for review April 17, 2023 20:32
@staabm staabm requested a review from TomasVotruba as a code owner April 17, 2023 20:32
@TomasVotruba
Copy link
Copy Markdown
Member

I think the failling job shows us one of the side-effects I mentioned in #3502 (comment).

It must be fixed before this gets merged, so we have always updated and working code here. Could you handle it?

@staabm
Copy link
Copy Markdown
Contributor Author

staabm commented Apr 18, 2023

I think the test here would be green after rectorphp/rector-symfony#391 is merged.

I was not able to test it though.

@samsonasik
Copy link
Copy Markdown
Member

build restarted

@samsonasik
Copy link
Copy Markdown
Member

@staabm test still error unfortunately

@samsonasik
Copy link
Copy Markdown
Member

@staabm I am reverting your PR rectorphp/rector-symfony#392

@staabm staabm changed the title Simplify isObjectTypeOfObjectType() Remove runtime autoloading from NodeTypeResolver Apr 19, 2023
@staabm
Copy link
Copy Markdown
Contributor Author

staabm commented Apr 19, 2023

should be good to go now. no changes in rector-symfony are needed anymore

$resolvedClassReflection = $this->reflectionProvider->getClass($resolvedObjectType->getClassName());

if ($this->traitExistsCache[$classReflection->getName()]) {
foreach ($classReflection->getAncestors() as $ancestorClassReflection) {
Copy link
Copy Markdown
Contributor Author

@staabm staabm Apr 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this ancestor traversal is slow.

after this PR we only do it for trait-classes. before we did it for every class, which was unnecessary, as only traits can be contained in a traitUse.

@staabm
Copy link
Copy Markdown
Contributor Author

staabm commented Apr 20, 2023

fixed, thanks

Copy link
Copy Markdown
Member

@samsonasik samsonasik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets give it a try, thank you @staabm

@samsonasik samsonasik merged commit 9f5d6b9 into rectorphp:main Apr 20, 2023
@staabm staabm deleted the simple branch April 20, 2023 10:59
@TomasVotruba
Copy link
Copy Markdown
Member

Thank you 😊

samsonasik pushed a commit that referenced this pull request May 8, 2023
* Remove runtime autoloading from NodeTypeResolver

* refactor
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.

4 participants