Do you use Easy Coding Standard? Do you find extremely useful and easy to use, but a little slow on a huge code base?
If you follow me carefully on Twitter, you already know that the ECS got a new parallel run feature. I wanted to test it in a circle of early adopters first, so we make the run as smooth as possible for you.
Today, we're sharing the ECS Parallel run with the public, so you can cut down ECS run times from minutes to seconds.
Have you already updated #ecs to parallel run? ☺️
— Tomas Votruba (@VotrubaT) October 7, 2021
This is what you're missing out ↓ pic.twitter.com/fuBKMpl8ID
Coding Standard tools are very fast in processing single file. They parse PHP code to tokens, analyze tokens in a foreach loop, and report found issues. The performance hit is in the number of processed files. If we have 10 files, the 1st file is processed. The 2nd file cannot start until the 1st file is finished.
Fortunately, this architecture has huge potential in performance improvement once we add a parallel run. That's what I've been working for July and August this summer. Huge thanks to Ondrej Mirtes for inspiration in PHPStan parallel run.
...where X = number of your CPU threads. What does it mean?
Let's say your CPU has 4 cores. The ECS was running for 60 seconds on your project. Now it runs 15 seconds. But there is more.
Some CPUs have 4 cores, but 8 threads. That means an improvement to 7,5 seconds.
You might think: "such CPUs must be expensive and available only for high-end laptops". You'll be surprised.
We've got few reports from our early adopters. How does ECS handle their projects?
Thanks, @VotrubaT for adding parallel run to ECS 🥰. Running on Shopware 6 needs now 24s instead of 229s. pic.twitter.com/cuxKy2ubfE
— Shyim (@Shyim97) October 11, 2021
How to add this feature to your project?
Be sure to use at least ECS 9.4.70:
composer require symplify/easy-coding-standard:^9.4.70
And enable a new parameter in your ecs.php
config file:
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\EasyCodingStandard\ValueObject\Option;
return function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
+ $parameters->set(Option::PARALLEL, true);
};
That's it!
The parallel run might become enabled by default in ECS 10. We have enough time to test it on real projects and make it reliable till then. So far, it has been tested on Linux and Windows. If you're lucky enough to find the edge case, please let us know in issues, so we can cover it.
Happy coding!
Do you learn from my contents or use open-souce packages like Rector every day?
Consider supporting it on GitHub Sponsors.
I'd really appreciate it!