Skip to content
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

[PoolOptimizer] Improve performance of keep package #10546

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Composer/DependencyResolver/PoolBuilder.php
Expand Up @@ -287,6 +287,8 @@ public function buildPool(array $repositories, Request $request)
$this->skippedLoad = array();
$this->indexCounter = 0;

$this->io->debug('Built pool.');

$pool = $this->runOptimizer($request, $pool);

Intervals::clear();
Expand Down Expand Up @@ -690,6 +692,9 @@ private function runOptimizer(Request $request, Pool $pool)
return $pool;
}

$this->io->debug('Running pool optimizer.');

$before = microtime(true);
$total = \count($pool->getPackages());

$pool = $this->poolOptimizer->optimize($request, $pool);
Expand All @@ -700,6 +705,7 @@ private function runOptimizer(Request $request, Pool $pool)
return $pool;
}

$this->io->write(sprintf('Pool optimizer completed in %.3f seconds', microtime(true) - $before), true, IOInterface::VERY_VERBOSE);
$this->io->write(sprintf(
'<info>Found %s package versions referenced in your dependency graph. %s (%d%%) were optimized away.</info>',
number_format($total),
Expand Down
5 changes: 5 additions & 0 deletions src/Composer/DependencyResolver/PoolOptimizer.php
Expand Up @@ -339,6 +339,11 @@ private function markPackageForRemoval($id)
*/
private function keepPackage(BasePackage $package, $identicalDefinitionsPerPackage, $packageIdenticalDefinitionLookup)
{
// Already marked to keep
if (!isset($this->packagesToRemove[$package->id])) {
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO this should use array_key_exists instead.

But maybe just personal preference :-)

Copy link
Member

Choose a reason for hiding this comment

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

isset is faster AFAIK as it's not a function, but as per https://gist.github.com/alcaeus/536156663fac96744eba77b3e133e50a it seems the PHP 8 benchmarks have them pretty much equal. But anyway I am happy with isset here.

return;
}

unset($this->packagesToRemove[$package->id]);

if ($package instanceof AliasPackage) {
Expand Down