-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve performance of DefaultPolicy #10585
Conversation
169bf3e
to
1d0b089
Compare
1d0b089
to
1a4e239
Compare
|
||
foreach ($packages as &$nameLiterals) { | ||
usort($nameLiterals, function ($a, $b) use ($pool, $requiredPackage): int { | ||
return $this->compareByPriority($pool, $pool->literalToPackage($a), $pool->literalToPackage($b), $requiredPackage, true); | ||
usort($nameLiterals, function ($a, $b) use ($pool, $requiredPackage, $poolId): int { |
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.
Have you tried caching the whole result like sort($nameLiterals); $cacheKey = implode(',', $nameLiterals);
then memoize the whole usort() call instead of every individual comparison?
I am not entirely sure if the combinations of literals here will vary so much that it makes it useless or not.. But if not I guess it'd be even more efficient. Gotta try this with various projects though
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 a complete match is pretty unlikely to happen. We compare within the dependency groups. So we have a group for e.g. ^4.2
and ^4.3
etc. Having the exact same packages inside those groups sounds very unrealistic to me. But I'll run some tests to see how many hits we'd have.
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.
Turns out I was wrong :) There are actually also thousands of hits 馃コ Both caches have very high hit rates now. I had to fix the cache key of the sorting cache too. I forgot to consider $requiredPackage
.
Thanks |
Add memoization to selectPreferredPackages
The
$policy->selectPreferredPackages()
is another bottleneck in thePoolOptimizer
as we call it for every dependency group which can easily happen for 10 000+ times on medium size projects. Most packages match to a lot of dependency groups so we actually compare the same packages over and over again to sort them within oneselectPreferredPackages()
call. The respective 2usort()
calls were actually responsible for up to 25% of the wholePoolOptimizer::optimize()
process.With this PR we're now caching the result so the sorting can be way faster (another 0.5 - 1 seconds down on the
PoolOptimizer
).Because we're using the
PolicyInterface
andPool $pool
is an argument, we have to make sure the cache is specific to the$pool
instance. Thanks to the new PHP 7.2 requirement, we can use the fasterspl_object_id()
for that 馃槑