From 324b57d6ae3e2b0141f6927fe689959654e78b33 Mon Sep 17 00:00:00 2001 From: characteristic Date: Tue, 4 Sep 2018 08:12:02 -0500 Subject: [PATCH] Correct Jinja2 plugin math filter symmetric_difference() to not repeatedly (#45093) build its intersection set and unnecessarily unique the final result. The prior use of the intersect() function within the list comprehension conditional leads to the function being called for every value in the input list being processed, not efficient. When the input lists a,b are large, the Ansible run time and resource utilization wildly increases generally never completing the operation. Unique of the intersection result is unnecessary as the source list union() is already unique. --- lib/ansible/plugins/filter/mathstuff.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/ansible/plugins/filter/mathstuff.py b/lib/ansible/plugins/filter/mathstuff.py index 390727b8c6f..403f7523822 100644 --- a/lib/ansible/plugins/filter/mathstuff.py +++ b/lib/ansible/plugins/filter/mathstuff.py @@ -65,7 +65,8 @@ def symmetric_difference(a, b): if isinstance(a, collections.Hashable) and isinstance(b, collections.Hashable): c = set(a) ^ set(b) else: - c = unique([x for x in union(a, b) if x not in intersect(a, b)]) + isect = intersect(a, b) + c = [x for x in union(a, b) if x not in isect] return c