-
Notifications
You must be signed in to change notification settings - Fork 516
Lazy initialization of AnalyserResult::$errors #2400
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
You've opened the pull request against the latest branch 1.11.x. If your code is relevant on 1.10.x and you want it to be released sooner, please rebase your pull request and change its target to 1.10.x. |
Can you please share a use case where AnalyserResult is created but errors aren't read? Thank you. |
@ondrejmirtes i think this isn't in relation to them being created but not read, but more to avoid the cost of sorting twice on line 80 of AnalyseApplication there is this: $intermediateAnalyserResult = $this->runAnalyser( which produces an $intermediateAnalyserResult = new AnalyserResult(
array_merge($intermediateAnalyserResult->getErrors(), $stubErrors), which will re-sort the errors, including any additional errors produced in stubs this change makes it so that the errors are only sorted once |
@mad-briller Are you sure? There's |
yeah, the |
But after this PR they will get sorted twice anyway, right? |
the pr actually changes the call to $intermediateAnalyserResult = new AnalyserResult(
array_merge($intermediateAnalyserResult->getUnorderedErrors(), $stubErrors),
``` |
I get it now 😊 |
Thank you. |
@mad-briller |
AnalyserResult::$errors
array is sorted in the class' constructor, but it doesn't always need to be sorted.This PR makes the property be initialized when
getErrors
is called.In
AnalyseApplication::analyse
we may get twoAnalyserResult
instances. One of them is just an intermediate result, so its error array doesn't have to be sorted.Sorting an array with
usort
may take a few seconds if the array has thousands of elements.