Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Short circuit if all checks disabled #8715

Closed
difhel opened this issue May 25, 2023 · 8 comments · Fixed by #8799 or #9093
Closed

Short circuit if all checks disabled #8715

difhel opened this issue May 25, 2023 · 8 comments · Fixed by #8799 or #9093
Milestone

Comments

@difhel
Copy link

difhel commented May 25, 2023

Bug description

Running "pylint test.py --disable=all" takes more than 3s!

$ touch test.py
$ time pylint test.py --disable=all

real    0m3.684s
user    0m0.000s
sys     0m0.015s

Running pylint without "disable=all" on a little project (150-lines telegram bot) takes more than 8s. It is non-usable.

$ time pylint main.py
************* Module main
main.py:137:7: R0133: Comparison between constants: '0 == 1' has a constant value (comparison-of-constants)
main.py:147:0: C0116: Missing function or method docstring (missing-function-docstring)

------------------------------------------------------------------
Your code has been rated at 9.57/10 (previous run: 9.57/10, +0.00)


real    0m8.352s
user    0m0.000s
sys     0m0.000s

Configuration

No response

Command used

pylint test.py

Pylint output

...

Expected behavior

It is unacceptable that even on an empty file pylint runs for at least 3 seconds. I use the VS Code extension in my project, which for a small example with a 150-line project reacts to changes in 8 (!) seconds. This is literally impossible to use.

Pylint version

$ pylint --version
pylint 2.17.4
astroid 2.15.5
Python 3.11.2 (tags/v3.11.2:878ead1, Feb  7 2023, 16:38:35) [MSC v.1934 64 bit (AMD64)]

OS / Environment

Windows 11

Additional dependencies

No response

@difhel difhel added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label May 25, 2023
@Pierre-Sassoulas
Copy link
Member

Hello, are you using any particular libraries or code construct ? As it is it's going to be impossible to reproduce.

@Pierre-Sassoulas Pierre-Sassoulas added performance Cannot reproduce 🤷 and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels May 26, 2023
@difhel
Copy link
Author

difhel commented May 26, 2023

The gpt4free repository was cloned in this project, I added it to ignore in the .pylintrc file. This reduced the running time by only 2 seconds.
Checking the file with "\n":

$ echo "\n" > test.py && time pylint test.py
************* Module test
test.py:1:2: E0001: Parsing failed: 'unexpected character after line continuation character (<unknown>, line 1)' (syntax-error)

real    0m1.639s
user    0m0.000s
sys     0m0.015s

Checking the bot file (150 lines):

$time pylint main.py
************* Module main
main.py:137:7: R0133: Comparison between constants: '0 == 1' has a constant value (comparison-of-constants)
main.py:147:0: C0116: Missing function or method docstring (missing-function-docstring)

------------------------------------------------------------------
Your code has been rated at 9.57/10 (previous run: 9.57/10, +0.00)


real    0m6.689s
user    0m0.000s
sys     0m0.031s

There are no big files in the working directory.
I created an empty file in empty folder, here is the output of pylint:

$ mkdir pylint-testing && cd pylint-testing

$ touch test.py

$ time pylint test.py --disable=all

real    0m1.616s
user    0m0.000s
sys     0m0.015s

$ time pylint test.py

real    0m1.592s
user    0m0.000s
sys     0m0.000s

I don't think it's a problem of specific libraries. If you want me to share any logs or traces with you, let me know.

@difhel
Copy link
Author

difhel commented May 26, 2023

I tested my code with flake8 and pycodestyle (aka pep8). There are results:

$ time flake8 main.py
main.py:27:80: E501 line too long (80 > 79 characters)
main.py:66:80: E501 line too long (82 > 79 characters)
main.py:80:80: E501 line too long (88 > 79 characters)
main.py:97:80: E501 line too long (81 > 79 characters)
main.py:114:67: E261 at least two spaces before inline comment
main.py:114:80: E501 line too long (111 > 79 characters)
main.py:118:80: E501 line too long (83 > 79 characters)
main.py:123:67: E261 at least two spaces before inline comment
main.py:123:80: E501 line too long (111 > 79 characters)
main.py:125:80: E501 line too long (85 > 79 characters)
main.py:127:80: E501 line too long (88 > 79 characters)
main.py:135:80: E501 line too long (98 > 79 characters)
main.py:137:15: E261 at least two spaces before inline comment
main.py:143:80: E501 line too long (82 > 79 characters)

real    0m0.673s
user    0m0.000s
sys     0m0.000s
$ time pycodestyle main.py
main.py:27:80: E501 line too long (80 > 79 characters)
main.py:66:80: E501 line too long (82 > 79 characters)
main.py:80:80: E501 line too long (88 > 79 characters)
main.py:97:80: E501 line too long (81 > 79 characters)
main.py:114:67: E261 at least two spaces before inline comment
main.py:114:80: E501 line too long (111 > 79 characters)
main.py:118:80: E501 line too long (83 > 79 characters)
main.py:123:67: E261 at least two spaces before inline comment
main.py:123:80: E501 line too long (111 > 79 characters)
main.py:125:80: E501 line too long (85 > 79 characters)
main.py:127:80: E501 line too long (88 > 79 characters)
main.py:135:80: E501 line too long (98 > 79 characters)
main.py:137:15: E261 at least two spaces before inline comment
main.py:143:80: E501 line too long (82 > 79 characters)

real    0m0.301s
user    0m0.015s
sys     0m0.000s

I understand that pylint does a deeper analysis, but that shouldn't increase the check time by 6 seconds.

@mbyrnepr2
Copy link
Member

Duplicate of #5933 @Pierre-Sassoulas ?

@Pierre-Sassoulas
Copy link
Member

Or pylint-dev/astroid#2161, but I don't think those perf issues are that bad so I suppose it's a pathological case on a specific lib / code construct and not a duplicate.

@jacobtylerwalls
Copy link
Member

Could you use a profiler like cProfile and post the result? You can profile:

from pylint.lint import Run
Run(["a.py", "disable=all"])

@jacobtylerwalls jacobtylerwalls added the Waiting on author Indicate that maintainers are waiting for a message of the author label May 30, 2023
@jacobtylerwalls
Copy link
Member

There are no big files in the working directory.

The size of the files is not material; it's what they import. If you import pandas, pylint is going to parse and replace the AST for pandas. That's going to take some time--it's part of pylint's distinct value proposition versus ruff, flake8, etc.

That said, I've seen a sprinkle of bug reports about --disable=all taking non-trivial time, so we may as well short circuit and just print the help message if a user disables everything.

@jacobtylerwalls jacobtylerwalls removed Cannot reproduce 🤷 Waiting on author Indicate that maintainers are waiting for a message of the author labels Jun 26, 2023
@jacobtylerwalls jacobtylerwalls changed the title Perfomance issue (2.17.4) Short circuit if all checks disabled Jun 26, 2023
@jacobtylerwalls
Copy link
Member

I rescoped it to "short circuit if all checks disabled" to make it actionable, but if you have a specific import statement you can share to advance the investigation, feel free to provide it. Otherwise it would be a duplicate of #5835 or #1416. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants