Skip to content

pylint is extremely slow on Generic classes #4079

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

Closed
jolaf opened this issue Feb 9, 2021 · 2 comments
Closed

pylint is extremely slow on Generic classes #4079

jolaf opened this issue Feb 9, 2021 · 2 comments
Labels
Astroid Related to astroid Enhancement ✨ Improvement to a component performance

Comments

@jolaf
Copy link

jolaf commented Feb 9, 2021

The following code:
testGenerics.py

from typing import Generic, TypeVar

T = TypeVar('T')

class A(Generic[T]): pass
class B(A[T]): pass
class C(B[T]): pass
class D(C[T]): pass
class E(D[T]): pass
class F(E[T]): pass
class G(F[T]): pass

print("OK")

produces the following output:

$ python3 testGenerics.py 
OK

$ mypy testGenerics.py 
Success: no issues found in 1 source file

$ time pylint testGenerics.py 
--------------------------------------------------------------------
Your code has been rated at 10.00/10 (previous run: 10.00/10, +0.00)

real	0m32.662s
user	0m32.219s
sys	0m0.233s

$ pylint --version
pylint 2.6.0
astroid 2.4.2
Python 3.8.5 (default, Jul 28 2020, 12:59:40) 
[GCC 9.3.0]

Note the 32 seconds run time.

Increasing the number of generic classes in a chain can easily bump the pylint run time to an hour or more.

The similar code without generics:
testNoGenerics.py

class A(): pass
class B(A): pass
class C(B): pass
class D(C): pass
class E(D): pass
class F(E): pass
class G(F): pass

print("OK")

has no such problems:

$ python3 testNoGenerics.py 
OK

$ time pylint testNoGenerics.py 

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

real	0m1.505s
user	0m1.340s
sys	0m0.127s
@robin-wayve
Copy link
Contributor

I'm not sure this example is still slow: I just had it pass in 2 seconds on Pylint 2.9.6 🤔

@Pierre-Sassoulas
Copy link
Member

Closing because we went from "painfully slow" to "normal pylint slowness" on this particular use case. See #4814 for startup time performance issue that explain the 2s.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Astroid Related to astroid Enhancement ✨ Improvement to a component performance
Projects
None yet
Development

No branches or pull requests

3 participants