diff options
author | Claudiu Popa <pcmanticore@gmail.com> | 2018-10-10 14:36:44 +0200 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2018-10-10 14:36:50 +0200 |
commit | 7513622d90eecf73f6259b310cab33d665e91ced (patch) | |
tree | 7698daa0c4374e7d631cc88cc62140d112f8edb5 /astroid/mixins.py | |
parent | e4c0d85f2fd6c87f4f763e93e7973c24ae98006b (diff) | |
download | astroid-git-7513622d90eecf73f6259b310cab33d665e91ced.tar.gz |
Cache the result of get_assign_nodes
The result is usually static, but we're hitting this function quite
a lot for big projects such as pandas. This change is a matter of compromising
between the amount of memory astroid needs for analysis (e.g. storing the
results in memory) vs the wasted CPU time in calling the same
function over and over.
Diffstat (limited to 'astroid/mixins.py')
-rw-r--r-- | astroid/mixins.py | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/astroid/mixins.py b/astroid/mixins.py index cec4b4bc..497a8400 100644 --- a/astroid/mixins.py +++ b/astroid/mixins.py @@ -12,6 +12,7 @@ """This module contains some mixins for the different nodes. """ +import itertools from astroid import decorators from astroid import exceptions @@ -142,10 +143,14 @@ class MultiLineBlockMixin: continue yield from child_node._get_yield_nodes_skip_lambdas() + @decorators.cached def _get_assign_nodes(self): - for block in self._multi_line_blocks: - for child_node in block: - yield from child_node._get_assign_nodes() + children_assign_nodes = ( + child_node._get_assign_nodes() + for block in self._multi_line_blocks + for child_node in block + ) + return list(itertools.chain.from_iterable(children_assign_nodes)) class NoChildrenMixin: |