
This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.
Created on2017-07-20 17:15 bywbolster, last changed2022-04-11 14:58 byadmin. This issue is nowclosed.
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 2785 | closed | wbolster,2017-07-20 17:15 | |
| PR 9078 | merged | taleinat,2018-09-06 07:01 | |
| PR 9106 | merged | taleinat,2018-09-07 21:11 | |
| PR 9133 | merged | taleinat,2018-09-10 12:53 | |
| Messages (11) | |||
|---|---|---|---|
| msg298738 -(view) | Author: wouter bolsterlee (wbolster)* | Date: 2017-07-20 17:15 | |
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 beset: 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+ Command23020 wbolster 20 0 315M 253M 7256 S 0.0 1.6 0:04.98 pythonwith slots:>>> import uuid>>> y = {uuid.uuid4() for _ in range(1000000)} PID USER PRI NI VIRT RES SHR S CPU% MEM% TIME+ Command21722 wbolster 20 0 206M 145M 7348 S 0.0 0.9 0:05.03 pythoni will open a pr on github shortly. | |||
| msg298739 -(view) | Author: wouter bolsterlee (wbolster)* | Date: 2017-07-20 17:19 | |
as a follow-up note, i also experimented with keeping the actual value as a bytes object instead of an integer, but that does not lead to less memory being used: a 128-bit integer uses less memory than a 16 byte bytes object (presumably because PyBytesObject has a cached hash() field and a trailing null byte). | |||
| msg298757 -(view) | Author: Nir Soffer (Nir Soffer) | Date: 2017-07-21 00:56 | |
This saves memory, but using str(uuid.uuid4()) requires even less memory.If you really want to save memory, you can keep the uuid.uuid4().int.Can you explain someone would like to have 1000000 uuid objects, instead of 1000000 strings? What is the advantage of keeping UUID objects around? | |||
| msg298785 -(view) | Author: wouter bolsterlee (wbolster)* | Date: 2017-07-21 08:57 | |
i consider uuids as low level data types, not as fancy containers, similar to how i view datetime objects. given the native support in e.g. postgresql and many other systems, it's common to deal with uuids.of course you can convert to/from strings or numbers, but that is cumbersome in many cases. for comparison, one would typically not convert unicode text from/into utf-8 encoded byte strings either, even though the latter will save memory in many cases.from experience: converting can lead to nasty bugs, e.g. because you forgot about a conversion, and then a uuid string does not compare equal to a uuid.UUID instance, leaving you puzzled. | |||
| msg303194 -(view) | Author: Serhiy Storchaka (serhiy.storchaka)*![]() | Date: 2017-09-28 07:05 | |
This change breaks pickle.You should preserve forward and backward pickle compatibility.1. Pickle data produced by old Python versions should be unpickleable with a new implementation. Implement __setstate__ for satisfying this.2. Pickle data produced by a new implementation should be unpickleable in old Python versions. There are many ways to satisfy this, you should choose the most efficient. | |||
| msg324665 -(view) | Author: Tal Einat (taleinat)*![]() | Date: 2018-09-06 07:10 | |
See new PR which addresses pickle forward and backward compatibility. | |||
| msg324671 -(view) | Author: STINNER Victor (vstinner)*![]() | Date: 2018-09-06 08:25 | |
I close the issue because of the pickle issue that hasn't been addressed by the wouter bolsterlee (the author) didn't reply for 1 month 1/2.@wouter bolsterlee: if you still want to work on that issue, you should try to address the pickle issue first, then reopen this issue or maybe create a new issue pointing to this one. | |||
| msg324672 -(view) | Author: STINNER Victor (vstinner)*![]() | Date: 2018-09-06 08:26 | |
Oops. I missed the fact that Tal createdPR 9078. Sorry, I reopen the issue ;-) | |||
| msg324682 -(view) | Author: Tal Einat (taleinat)*![]() | Date: 2018-09-06 11:34 | |
New changeset3e2b29dccc3ca9fbc418bfa312ad655782e250f2 by Tal Einat in branch 'master':bpo-30977: make uuid.UUID use __slots__ (GH-9078)https://github.com/python/cpython/commit/3e2b29dccc3ca9fbc418bfa312ad655782e250f2 | |||
| msg324683 -(view) | Author: Tal Einat (taleinat)*![]() | Date: 2018-09-06 11:35 | |
Thanks for the suggestion and the original patch, Wouter! | |||
| msg324923 -(view) | Author: Tal Einat (taleinat)*![]() | Date: 2018-09-10 13:11 | |
New changeset54752533b2ed1c898ffe5ec2e795c6910ee46a39 by Tal Einat in branch 'master':bpo-30977: rework code changes according to post-merge code review (GH-9106)https://github.com/python/cpython/commit/54752533b2ed1c898ffe5ec2e795c6910ee46a39 | |||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:58:49 | admin | set | github: 75160 |
| 2018-09-10 13:11:09 | taleinat | set | messages: +msg324923 |
| 2018-09-10 12:53:14 | taleinat | set | pull_requests: +pull_request8586 |
| 2018-09-07 21:11:41 | taleinat | set | pull_requests: +pull_request8560 |
| 2018-09-06 11:35:57 | taleinat | set | status: open -> closed resolution: fixed messages: +msg324683 |
| 2018-09-06 11:34:32 | taleinat | set | messages: +msg324682 |
| 2018-09-06 08:26:25 | vstinner | set | status: closed -> open resolution: out of date -> (no value) messages: +msg324672 |
| 2018-09-06 08:25:48 | vstinner | set | status: open -> closed resolution: out of date messages: +msg324671 stage: patch review -> resolved |
| 2018-09-06 07:10:39 | taleinat | set | nosy: +taleinat messages: +msg324665 |
| 2018-09-06 07:01:08 | taleinat | set | keywords: +patch stage: patch review pull_requests: +pull_request8536 |
| 2018-02-04 08:06:17 | serhiy.storchaka | set | versions: + Python 3.8, - Python 3.7 |
| 2017-09-28 13:38:35 | vstinner | set | nosy: +vstinner |
| 2017-09-28 07:05:25 | serhiy.storchaka | set | versions: + Python 3.7 nosy: +serhiy.storchaka messages: +msg303194 components: + Library (Lib) type: resource usage |
| 2017-07-21 08:57:53 | wbolster | set | messages: +msg298785 |
| 2017-07-21 00:56:24 | Nir Soffer | set | nosy: +Nir Soffer messages: +msg298757 |
| 2017-07-20 17:19:58 | wbolster | set | messages: +msg298739 |
| 2017-07-20 17:15:59 | wbolster | set | pull_requests: +pull_request2835 |
| 2017-07-20 17:15:28 | wbolster | create | |