laravel / pint

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

Performance tuning & optimizations #121

Closed dbhynds closed 2 years ago

dbhynds commented 2 years ago

We're running a large Laravel app. We've been using https://packagist.org/packages/jubeki/laravel-code-style for a long time which is also built on php-cs-fixer. I was experimenting with how easy it would be swap Pint in for our old linter.

In attempting to do so, I noticed some major performance issues with Pint. We run a linter in CI on every commit. Our old linter typically took about 45 seconds to execute. By comparison, Pint takes about 7 minutes. This is odd, given that both are built on php-cs-fixer. Something about Pint seems to be seriously slowing things down. We have an SLO that all CI jobs finish in <5 minutes, meaning that as-is Pint isn't a viable option for us.

Do you have any recommendations for how we could improve performance? I poked around this repo and the docs on laravel.com, and the there's not much in the way of configuration options that I can see.

(Note: I noticed that after I run the Pint locally, it caches everything, and runs quickly. However in CI, we won't have access to previous cached data).

driesvints commented 2 years ago

Hi there. This would seem odd to me. We also use Pint in CI and it typically takes 20-40 seconds for us to run. So my best guess is that there's something in your project specifically that's going wrong.

Here's the action we use which you can take as an example, but we don't do anything special there: https://github.com/laravel/.github/blob/main/.github/workflows/coding-standards.yml

If you need further help please try a support channel:

calebdw commented 1 year ago

@dbhynds,

Not sure if you've figured this out yet or not, but I was having the same issue and was able to speed up the pipeline linting by defining/caching the pint cache (by default Pint uses the system tmp directory).

  1. Define a cache file in pint.json: "cache-file": "pint.cache".
  2. Cache file in pipeline (I use Gitlab):
      cache:
        # per branch caching
        key: $CI_COMMIT_REF_SLUG
        paths:
          - pint.cache

Doing this dropped the linting from > 11 minutes to under 1 minute. The caveat is that the first commit for a branch will take the full time of course.

Note that I ignore the pint cache, but I suppose you could commit it and that would ensure the pipelines always have it.