1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

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.
This commit is contained in:
James Cammarata 2017-02-10 14:34:37 -06:00
parent 84135ef7ad
commit 4cbe610263
2 changed files with 4 additions and 7 deletions

View file

@ -19,10 +19,8 @@
from __future__ import (absolute_import, division, print_function) from __future__ import (absolute_import, division, print_function)
__metaclass__ = type __metaclass__ = type
import uuid
from ansible.inventory.group import Group 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'] __all__ = ['Host']
@ -92,7 +90,7 @@ class Host:
self._gathered_facts = False self._gathered_facts = False
self._uuid = None self._uuid = None
if gen_uuid: if gen_uuid:
self._uuid = uuid.uuid4() self._uuid = get_unique_id()
self.implicit = False self.implicit = False
def __repr__(self): def __repr__(self):

View file

@ -21,7 +21,6 @@ __metaclass__ = type
import itertools import itertools
import operator import operator
import uuid
from copy import copy as shallowcopy from copy import copy as shallowcopy
from functools import partial 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.playbook.attribute import Attribute, FieldAttribute
from ansible.parsing.dataloader import DataLoader from ansible.parsing.dataloader import DataLoader
from ansible.constants import mk_boolean as boolean 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: try:
from __main__ import display from __main__ import display
@ -184,7 +183,7 @@ class Base(with_metaclass(BaseMeta, object)):
self._finalized = False self._finalized = False
# every object gets a random uuid: # 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 # 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 # it was intialized as a class param in the meta class, so we