-
-
Notifications
You must be signed in to change notification settings - Fork 276
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
Make import astroid
faster (again)
#2161
Comments
Doesn't |
I think the problem might lie in astroid/astroid/raw_building.py Line 729 in faea711
astroid/astroid/raw_building.py Lines 597 to 601 in faea711
astroid/astroid/raw_building.py Lines 592 to 594 in faea711
|
Yeah, that is the building of the |
I tried doing it lazily with: diff --git a/astroid/manager.py b/astroid/manager.py
index 7f62fd42..f88b7360 100644
--- a/astroid/manager.py
+++ b/astroid/manager.py
@@ -87,6 +87,11 @@ class AstroidManager:
@property
def builtins_module(self) -> nodes.Module:
+ if "builtins" not in self.astroid_cache:
+ from astroid.raw_building import _astroid_bootstrapping
+
+ _astroid_bootstrapping()
+
return self.astroid_cache["builtins"]
def visit_transforms(self, node: nodes.NodeNG) -> InferenceResult:
diff --git a/astroid/raw_building.py b/astroid/raw_building.py
index 45eeb10b..4cb38438 100644
--- a/astroid/raw_building.py
+++ b/astroid/raw_building.py
@@ -724,6 +724,3 @@ def _astroid_bootstrapping() -> None:
)
builder.object_build(klass, _type)
astroid_builtin[_type.__name__] = klass
-
-
-_astroid_bootstrapping() Importing astroid.raw_building is faster but the import time seems equivalent overall (maybe slightly faster but definitely not noticeably). It's probably built at import time anyway, because we instantiate an astroid Manager (?) Don't know if it's possible/reasonable to instantiate the manager in the calling code. |
The import time was more than halved on my machine (after importing once). First import is 330ms before, 300ms after, but subsequent one are 150ms before, 60ms after. The final result (hot cache) for reference:
Biggest import time now are:
Which is to be expected there's a lot inside those module (and it's now shorter than importing |
Steps to reproduce
Current behavior
Currently astroid import time account for 25+% of the parse time for single file analysis in pylint (common with parallelized pre-commit hook). This is 50+% with
--disable=all
. This is a follow up to #1320 where the import time was already decreased by 60%. We can see that importingastroid.raw_building
now takes 60% of the remaining import time,astroid.nodes._base_nodes
(3.5%) andastroid.nodes.node_classes
(1,7%) are the next biggest offenders that we control.Expected behavior
Faster astroid import to make pylint more reactive.
The text was updated successfully, but these errors were encountered: