-
Notifications
You must be signed in to change notification settings - Fork 551
NodeScopeResolver: Prevent repetitive union of static types #4841
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
Conversation
src/Analyser/NodeScopeResolver.php
Outdated
| $this->earlyTerminatingMethodNames = $earlyTerminatingMethodNames; | ||
|
|
||
| $this->nonIntKeyOffsetValueType = TypeCombinator::union( | ||
| new ArrayType(new MixedType(), new MixedType()), |
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.
Would be better if it was lazily initialized with ??= right before usage.
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 think the NodeScopeResolve is created once for the whole analysis and its pretty likely that we hit the path on usage.
so I think there is not much to be saved. only difference would be readability, as we would move code more to a single place (but we will also loose readonly attribute)
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.
so its a matter of code readability, not performance.
if you prefer I can move it to a ??=
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 worry about doing things in constructor. For example if NodeScopeResolver depended on ReflectionProvider or vice-versa, doing something related to Type objects in constructor could lead to infinite recursion.
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.
good points, didn't think about that.
|
Thank you! |
|
Maybe I'm missing something but can't the If not and if we're starting caching some often used Union to reduce the number of call of |
|
It's true it could be new UnionType, but this will be literally a single call during the analysis so it's not going to cost us any time. |
I thought that without the need of using But I'm not familiar at all with perf/memory costs and never work to improve a codebase about it, so I rely on your and staabm's experience. |
I wouldn't say the goal is to save all the the change was done to get rid of a hot path. it does not mean similar pattern in other less-hot path should be treated the same. |
before PR
after PR -
unionno longer appears as one of the callees