Skip to content

Speedup Composer by downloading packages in parallel #261

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

Merged
merged 1 commit into from
Jan 3, 2018
Merged

Speedup Composer by downloading packages in parallel #261

merged 1 commit into from
Jan 3, 2018

Conversation

nicolas-grekas
Copy link
Member

@nicolas-grekas nicolas-grekas commented Jan 2, 2018

Purpose

This PR is heavily inspired by the great hirak/prestissimo by Hiraku NAKANO.

Its purpose is to provide a portable alternative to hirak/prestissimo, so that it can be bundled by default into Flex: unlike hirak/prestissimo, it doesn't require the curl extension and has zero extra dependencies. Instead, it reuses the existing code infrastructure in Composer to download packages.

If hirak/prestissimo is installed, this behavior disables itself automatically.

Limitations

  • By reusing Composer's downloader, it is not possible to create server connections concurrently.
    Instead, the second download is started when the first one receives its first bytes from the server, and so on.
  • JSON files downloaded from package repositories (e.g. from packagist.org) are still loaded sequentially (could be improved, PR welcome.)
  • Packages installed by cloning source code repositories are not parallelized (neither with hirak/prestissimo.)

(striked limitations removed by #286)

@nicolas-grekas
Copy link
Member Author

composer create-project symfony/skeleton demo

  • 30s native, 16s with this PR, 9s with prestissimo - that's the curl advantage we cannot rely on

installing 134 packages on Blackfire

  • 3m45s native, 2min with this PR, prestissimo 35s (but needs cURL)

@@ -250,6 +253,21 @@ public function executeAutoScripts(Event $event)
$this->io->write($this->postInstallOutput);
}

public function populateCacheDir(InstallerEvent $event)
{
if (extension_loaded('curl') && class_exists(Prestissimo::class, false)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you sure Prestissimo is the right class? I can't find it on https://github.com/hirak/prestissimo

Copy link
Member Author

Choose a reason for hiding this comment

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

missing alias, fixed thanks

@bitgandtter
Copy link

Can we include a validation for the cURL ext and if its enabled use that approach to gain the full speed?

@nicolas-grekas
Copy link
Member Author

@bitgandtter not sure what you mean, but using cURL is far from trivial - basically, that's what https://github.com/hirak/prestissimo provides, so just use it if you have curl.

@bitgandtter
Copy link

yes my bad @nicolas-grekas i miss the above check #261 (diff) that in fact was the intent of my comment

@GromNaN
Copy link
Member

GromNaN commented Jan 2, 2018

Thank you for your work on making symfony faster. This is a great plugin for composer totally decoupled from flex.

But Flex should be installed only as dev environments and this plugin will be useful for deployments, without dev requirements.

Making a separate package would be more powerful. Allowing non-flex developers to profit from this optimisation.
Or the package hirak/prestissimo could be updated to support this failsoft solution.

@fabpot
Copy link
Member

fabpot commented Jan 2, 2018

Flex is part of the require section, so always available. It's then the responsibility of Flex to do nothing in case of an install (for deployment), which is exactly what it does.

@LKaemmerling
Copy link

@nicolas-grekas why you doesn`t contribute this to Composer so every PHP Developer would profit from IT Not only Symfony Devs.

@nicolas-grekas
Copy link
Member Author

nicolas-grekas commented Jan 2, 2018

@GromNaN @LKDevelopment I'm focusing on improving the Symfony + Flex based experience that's correct. That's already enough work for one (even passionate) person.
The good news is that this is going to be released under a very permissive license so that anyone else could take over.
For myself, it serves my current motivation and goals (and available time for a balanced life.)

@nicolas-grekas
Copy link
Member Author

The technical answer is that things cannot be "just" added to Composer, nor released standalone: projects have policies, stability to ensure, maintenance to accept, etc. It could happen, but that's a significant effort. Better start with some pragmatic first step.

@fabpot
Copy link
Member

fabpot commented Jan 2, 2018

For the record, I think @nicolas-grekas even submitted a pull request on Composer to add such parallelization a long time ago... yep, 2.5 years ago, still open: composer/composer#3951

@staabm
Copy link

staabm commented Jan 3, 2018

with https://github.com/amphp/artax you can get a zero dependency (php-ext wise) http parallel (non-blocking) client, maybe this is an alternative to what you have right now (and I could provide better performance).

counter argument: I really like how simple this PR atm looks like.

@fabpot
Copy link
Member

fabpot commented Jan 3, 2018

Thank you @nicolas-grekas.

@fabpot fabpot merged commit 66d9609 into symfony:master Jan 3, 2018
fabpot added a commit that referenced this pull request Jan 3, 2018
…colas-grekas)

This PR was merged into the 1.0-dev branch.

Discussion
----------

Speedup Composer by downloading packages in parallel

Purpose
-------

This PR is heavily inspired by the great [hirak/prestissimo](https://github.com/hirak/prestissimo) by Hiraku NAKANO.

Its purpose is to provide a portable alternative to `hirak/prestissimo`, so that it can be bundled by default into Flex: unlike `hirak/prestissimo`, it doesn't require the `curl` extension and has zero extra dependencies. Instead, it reuses the existing code infrastructure in Composer to download packages.

If `hirak/prestissimo` is installed, this behavior disables itself automatically.

Limitations
-----------

- By reusing Composer's downloader, it is not possible to create server connections concurrently.
  Instead, the second download is started when the first one receives its first bytes from the server, and so on.
- JSON files downloaded from package repositories (e.g. from packagist.org) are still loaded sequentially (could be improved, PR welcome.)
- Packages installed by cloning source code repositories are not parallelized (neither with `hirak/prestissimo`.)

Commits
-------

66d9609 Speedup Composer by downloading packages in parallel
@nicolas-grekas nicolas-grekas deleted the allegretto branch January 3, 2018 11:41
tgalopin pushed a commit to tgalopin/flex that referenced this pull request Dec 3, 2020
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.

7 participants