From 12a6fb9633b8031df2dba5c2bdaba655af5241fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yannig=20Perr=C3=A9?= Date: Sat, 7 Nov 2015 19:32:10 +0100 Subject: [PATCH] Small speed improvement with huge inventory (100+ hosts). --- lib/ansible/playbook/base.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/ansible/playbook/base.py b/lib/ansible/playbook/base.py index 06681abe76..1d4a632bbd 100644 --- a/lib/ansible/playbook/base.py +++ b/lib/ansible/playbook/base.py @@ -37,6 +37,8 @@ from ansible.playbook.attribute import Attribute, FieldAttribute from ansible.utils.boolean import boolean from ansible.utils.vars import combine_vars, isidentifier +BASE_ATTRIBUTES = {} + class Base: # connection/transport @@ -123,12 +125,19 @@ class Base: Returns the list of attributes for this class (or any subclass thereof). If the attribute name starts with an underscore, it is removed ''' + + # check cache before retrieving attributes + if self.__class__ in BASE_ATTRIBUTES: + return BASE_ATTRIBUTES[self.__class__] + + # Cache init base_attributes = dict() for (name, value) in getmembers(self.__class__): if isinstance(value, Attribute): if name.startswith('_'): name = name[1:] base_attributes[name] = value + BASE_ATTRIBUTES[self.__class__] = base_attributes return base_attributes def _initialize_base_attributes(self):