PCI tracker: make O(M * N) clean_usage algo linear

By using sets instead of lists we can cut the runtime of a piece of code
that runs on every periodic resource update form quadratic to linear.
Easy win.

Change-Id: I7b0c1eb8188a428bf7e9f8dee710e9c46ed276eb
This commit is contained in:
Nikola Dipanov 2015-03-26 14:07:34 +00:00
parent aac16b0257
commit fc6442075a
1 changed files with 3 additions and 3 deletions

View File

@ -251,9 +251,9 @@ class PciDevTracker(object):
The caller should hold the COMPUTE_RESOURCE_SEMAPHORE lock
"""
existed = [inst['uuid'] for inst in instances]
existed += [mig['instance_uuid'] for mig in migrations]
existed += [inst['uuid'] for inst in orphans]
existed = set(inst['uuid'] for inst in instances)
existed |= set(mig['instance_uuid'] for mig in migrations)
existed |= set(inst['uuid'] for inst in orphans)
for uuid in self.claims.keys():
if uuid not in existed: