From 4cbe6102637eba5b70b70be582ef4bdaaaa910d5 Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Fri, 10 Feb 2017 14:34:37 -0600 Subject: [PATCH] Use a custom id generator over uuid4 >>> timeit.timeit("uuid.uuid4()", setup="import uuid") 9.518647909164429 >>> timeit.timeit("get_unique_id()", setup="from __main__ import get_unique_id") 0.40436601638793945 This will mainly be beneficial when a very large inventory is being used, however it may also help with some very large playbooks. --- lib/ansible/inventory/host.py | 6 ++---- lib/ansible/playbook/base.py | 5 ++--- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/lib/ansible/inventory/host.py b/lib/ansible/inventory/host.py index a48fbce6ff..8d0fc9a52c 100644 --- a/lib/ansible/inventory/host.py +++ b/lib/ansible/inventory/host.py @@ -19,10 +19,8 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import uuid - from ansible.inventory.group import Group -from ansible.utils.vars import combine_vars +from ansible.utils.vars import combine_vars, get_unique_id __all__ = ['Host'] @@ -92,7 +90,7 @@ class Host: self._gathered_facts = False self._uuid = None if gen_uuid: - self._uuid = uuid.uuid4() + self._uuid = get_unique_id() self.implicit = False def __repr__(self): diff --git a/lib/ansible/playbook/base.py b/lib/ansible/playbook/base.py index 41a437c22d..3e98e57579 100644 --- a/lib/ansible/playbook/base.py +++ b/lib/ansible/playbook/base.py @@ -21,7 +21,6 @@ __metaclass__ = type import itertools import operator -import uuid from copy import copy as shallowcopy from functools import partial @@ -34,7 +33,7 @@ from ansible.module_utils._text import to_text from ansible.playbook.attribute import Attribute, FieldAttribute from ansible.parsing.dataloader import DataLoader from ansible.constants import mk_boolean as boolean -from ansible.utils.vars import combine_vars, isidentifier +from ansible.utils.vars import combine_vars, isidentifier, get_unique_id try: from __main__ import display @@ -184,7 +183,7 @@ class Base(with_metaclass(BaseMeta, object)): self._finalized = False # every object gets a random uuid: - self._uuid = uuid.uuid4() + self._uuid = get_unique_id() # we create a copy of the attributes here due to the fact that # it was intialized as a class param in the meta class, so we