19

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.

Sahar
  • 741
  • 1
  • 8
  • 14
  • This Pylint issue might be relevant: [Pylint slow when run on script with pandas #2198](https://github.com/PyCQA/pylint/issues/2198) – user1071847 Oct 09 '18 at 19:51

3 Answers3

8

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]
Eugene Yarmash
  • 142,882
  • 41
  • 325
  • 378
2

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.

MatthewMartin
  • 32,326
  • 33
  • 105
  • 164
  • 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 '18 at 23:48
  • 1
    > PyCharm's inspections How are you supposed to run it in CI? Is it even a thing? – validname Jun 07 '22 at 13:04
  • @validname - Looks technically possible now: https://www.jetbrains.com/help/idea/command-line-code-inspector.html I didn't check if there are licensing challenges (probably are) – MatthewMartin Jun 07 '22 at 14:23
1

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.

Phenyl
  • 495
  • 1
  • 9
  • 13