21

I do not understand why pylint takes about 5 minutes to check my code, where pep8 takes only 1 sec.

I use Mac and I have pylint 1.8.4 installed through conda install -c conda-forge pylint. Pylint is very slow either I use Terminal or the Spyder editor. I tried creating a config file .pylintrc but it didn't make a difference to the speed.

How can I accelerate the Pylint speed? Thank you.

1

3 Answers 3

9

You can speed up pylint by spawning multiple processes and checking files in parallel. This functionality is exposed via the -j command-line parameter. If the provided number is 0, then the total number of CPUs will be autodetected and used. From the output of pylint --help:

-j <n-processes>, --jobs=<n-processes>
    Use multiple processes to speed up Pylint. Specifying
    0 will auto-detect the number of processors available
    to use. [current: 1]
2
  • 12
    I'm not finding this actually changing the performance. Jan 7, 2022 at 13:38
  • I moved to ruff, it's much much faster
    – Hritik
    Oct 18 at 10:10
2

This blog post gives a good performance analysis. pylint analyzes every line of code for two things:

  1. the code itself, obviously,
  2. the message control, also called pragma, i.e. comments like # pylint: disable=line-too-long.

While pragmas are a nice feature to add linter exceptions, they come to the expense of a more complex logic. Moreover, this features triggers additional checks when the line is too long, and when the module contains too many lines (source code as of Jan. 2023).

While I can fix my code, I cannot control the libraries I import. For instance, pandas has modules of 12k lines.

My workaround - Increase the max-line-length and max-module-lines parameters in .pylintrc, e.g. to 200 and 15000. No miracle here, but a visible improvement (not measured).

Note - Using -j or setting jobs does not work for me because it is used to process modules in parallel. It does not accelerate the linting of a single file, and syntastic calls the pylint on the current file only.

1

Some version of Pylint have performance problems, try rolling back a version or rolling forward to a newer version.

Smaller code bases seem to lint faster than larger ones, although I don't have any numbers to back that up.

Disable any rules that you don't plan to fix anyway- at one time spell checking in pylint was a problem.

Try a different tool - PyCharm's inspections covers a lot of similar ground and for the most part in my experience hasn't had the performance problems of pylint.

3
  • Thanks a lot! I will try your proposed solutions and will let you know which one could solve the speed problem I'm facing.
    – Sahar
    Sep 12, 2018 at 23:48
  • 2
    > PyCharm's inspections How are you supposed to run it in CI? Is it even a thing?
    – validname
    Jun 7, 2022 at 13:04
  • @validname - Looks technically possible now: jetbrains.com/help/idea/command-line-code-inspector.html I didn't check if there are licensing challenges (probably are) Jun 7, 2022 at 14:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.