[New-bugs-announce] [issue30977] reduce uuid.UUID() memory footprint
Wouter Bolsterlee
report at bugs.python.org
Thu Jul 20 13:15:28 EDT 2017
New submission from Wouter Bolsterlee:
memory usage for uuid.UUID seems larger than it has to be. it seems that using __slots__ will save around ~100 bytes per instance, which is very significant, e.g. when dealing with large sets of uuids (which are often used as "primary keys" into external data stores).
uuid.UUID has a __setattr__ that prevents any extra attributes to be
set:
def __setattr__(self, name, value):
raise TypeError('UUID objects are immutable')
...so it seems to me not having __dict__ should not cause any problems?
before (RES column):
>>> import uuid
>>> y = {uuid.uuid4() for _ in range(1000000)}
PID USER PRI NI VIRT RES SHR S CPU% MEM% TIME+ Command
23020 wbolster 20 0 315M 253M 7256 S 0.0 1.6 0:04.98 python
with slots:
>>> import uuid
>>> y = {uuid.uuid4() for _ in range(1000000)}
PID USER PRI NI VIRT RES SHR S CPU% MEM% TIME+ Command
21722 wbolster 20 0 206M 145M 7348 S 0.0 0.9 0:05.03 python
i will open a pr on github shortly.
----------
messages: 298738
nosy: wbolster
priority: normal
severity: normal
status: open
title: reduce uuid.UUID() memory footprint
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue30977>
_______________________________________
More information about the New-bugs-announce
mailing list