Faster-than-light composer on Mac with HHVM
Tristan Roussel3 min read
Hello my dearest Mac geeks!
A long long time ago, Facebook released a shiny machine named HHVM.
It could execute PHP very fast and was compatible with Mac OS X.
Time has passed, HHVM was still incredibly fast, but lost its compatibility with Mac.
A few days ago, after 2 years of intense work, a (too discreet in my opinion) announcement popped:
Awesomeness was back.
You can now (again) install HHVM on your Mac very easily with Homebrew thanks to this official repository:
brew tap hhvm/hhvm
brew install hhvm
A warning though, installation takes a long time (as in “can take more than 1 hour on slow computers”).
Awesome! Wait, what do I need HHVM for again?
Who has never had any performance problem with Composer?
Infamously, the composer update
command can be very slow and eat a lot of memory if you have quite a few dependencies, which is often the case on a Symfony project.
I ran out of memory several times because of it, generally after a few minutes of intense computation.
Situation is considerably better than in the past thanks to some incredible tricks like this one.
And yet, 2GB of RAM is rarely sufficient, and it still takes more than 5 minutes on some computers to update the configuration.
First thing to speed up composer:
if you work in a virtual machine with file sharing with your Mac (with Vagrant for example), you should not try composer update
inside the machine, but in your Mac.
That leads us to HHVM:
hhvm $(brew --prefix)/bin/composer.phar update
should rock your world on your Mac!
Don’t like to type all this gibberish?
Make it an alias.
For bash
for example, add this to your .bash_profile
:
alias hcomposer='hhvm $(brew --prefix)/bin/composer.phar'
Another warning, when updating outside your environment with either your Mac PHP or HHVM, you should use the option --ignore-platform-reqs
to ignore the version differences in PHP and the extensions.
Benchmark with “oldie” PHP 5.6.12 on a naked Symfony Standard Edition (on a quite newish MacBook Pro, so it’s still really fast):
composer update --profile
[8.0MB/0.07s] Loading composer repositories with package information
[8.4MB/0.20s] Updating dependencies (including require-dev)
[367.7MB/14.71s] - Installing symfony/symfony (2.8.x-dev 685a1cf)
[367.7MB/14.71s] Cloning 685a1cf6f441459fb61a25acfe93853d016f46c2
…
With shiny bleeding edge HHVM:
hcomposer update --profile
[8.0MB/1.16s] Loading composer repositories with package information
[8.0MB/1.64s] Updating dependencies (including require-dev)
[126.0MB/5.66s] - Installing symfony/symfony (2.8.x-dev 685a1cf)
[126.0MB/5.84s] Cloning 685a1cf6f441459fb61a25acfe93853d016f46c2
…
Now, your biggest problem will be finding a way to spend all this free time left for you.