From c889f08ab5279caae3d6fe4e0614fa938fb2c9ff Mon Sep 17 00:00:00 2001 From: Zane Bitter Date: Wed, 19 Jul 2017 17:35:40 -0400 Subject: [PATCH] Optimise the function.dep_attrs() function Due to unfortunate copy-pasta, the original implementation of function.dep_attrs() iterates over items in a dictionary instead of values. Dictionary keys cannot have dependencies - they must be hashable and Function objects are not. So for each dictionary key we call dep_attrs() recursively 3 times as many times as we need to (for the key/value tuple, the key, and the value). For template snippets that are dominated by dictionaries, this means it took three times as long and used three times as much memory and twice as much stack space as it needed to. Change-Id: I13781540483daf88202d221a9f517746eebf0346 Partial-Bug: #1684272 --- heat/engine/function.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/heat/engine/function.py b/heat/engine/function.py index 1aed951660..40d7a58c1f 100644 --- a/heat/engine/function.py +++ b/heat/engine/function.py @@ -289,7 +289,7 @@ def dep_attrs(snippet, resource_name): return snippet.dep_attrs(resource_name) elif isinstance(snippet, collections.Mapping): - attrs = (dep_attrs(value, resource_name) for value in snippet.items()) + attrs = (dep_attrs(val, resource_name) for val in snippet.values()) return itertools.chain.from_iterable(attrs) elif (not isinstance(snippet, six.string_types) and isinstance(snippet, collections.Iterable)):