laravel / pint

Laravel Pint is an opinionated PHP code style fixer for minimalists.
https://laravel.com/docs/pint
MIT License
2.78k stars 144 forks source link

Run Pint analysis in Parallel #275

Closed thbley closed 4 months ago

thbley commented 4 months ago

Pint Version

v1.16.0

PHP Version

8.3.7

Description

Currently pint is always running in sequential mode. Running in parallel would be very nice!

Problem probably related to FixCode::execute() line 60 missing arguments for ParallelConfig and InputInterface.

Steps To Reproduce

Normal execute, use top to verify that only 1 php process is running instead of multiple.

driesvints commented 4 months ago

Thanks for your proposal! Right now we don't have plans for this. Should you wish, you're free to attempt a PR yourself. Thanks!

thbley commented 4 months ago

Sorry to ask, but from the changelog, it looks like there are plans for parallel execution?

v1.16.0 Latest

[1.x] Enable Parallel Execution by @Jubeki in https://github.com/laravel/pint/pull/272
IronSinew commented 4 months ago

@driesvints https://github.com/laravel/pint/pull/272

Pint should be able to support running in parallel. I only see it running single-threaded as well.

Jubeki commented 4 months ago

As the Autor of the PR, I hoped, that pint would run in parallel without much of a hassle. But there could be more adjustments which need to be done, like something with building the binary. (This needs experimentation time and probably a good understanding about processes)

You are always free to try a PR, to make adjustments, so that pint actually runs in parallel. As this is only an improvement.

lribi commented 2 months ago

Looked a bit into this and I think there are several issues.

As initially mentioned above, due to the direct usage of Runner, ParallelConfig and InputInterface need to be passed as arguments (otherwise it will fallback to sequential).

The bigger issue is the way how processes are created here https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/master/src/Runner/Parallel/ProcessFactory.php#L27

In a phar realpath will not work and it seems as a workaround a check based on argv and php-cs-fixer is used to define the binary to be executed in spawned processes. Additionally the wrong assumption that several arguments are present in the input (when called through pint) will lead to issues.

I don't see a clean way to solve this using the current approach, without adjustments to PHP-CS-Fixer.

mortenscheel commented 2 weeks ago

In a project with ~5000 php files to analyze, it takes several minutes to run Pint. It feels like a major downgrade when switching from native php-cs-fixer.