From: Assaf Muller Date: Fri, 15 May 2015 21:58:13 +0000 (-0400) Subject: Optimize IptablesManager._find_last_entry X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=bf71868ba809587b72da68b8cd4c248cf33990a1;p=openstack-build%2Fneutron-build.git Optimize IptablesManager._find_last_entry As it turns out calling .strip() thousands of times can be expensive. I'll defer to security groups and iptables experts to try and find ways to call the method less often, cache the results, or any other clever trick. Moving strip to the return statement speeds up the method by more than x2. Change-Id: I7522c6db50c76274bef93e0f0ea6a78d508b7fbe Related-Bug: #1455675 --- diff --git a/neutron/agent/linux/iptables_manager.py b/neutron/agent/linux/iptables_manager.py index ed99155d1..f63098681 100644 --- a/neutron/agent/linux/iptables_manager.py +++ b/neutron/agent/linux/iptables_manager.py @@ -506,9 +506,8 @@ class IptablesManager(object): def _find_last_entry(self, filter_list, match_str): # find a matching entry, starting from the bottom for s in reversed(filter_list): - s = s.strip() if match_str in s: - return s + return s.strip() def _modify_rules(self, current_lines, table, table_name): # Chains are stored as sets to avoid duplicates.