Issue 22131: uuid.bytes optimization - Python tracker (original) (raw)

Created on 2014-08-04 02:05 by kevinlondon, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
uuid_bytes_update.patch kevinlondon,2014-08-04 02:05 A patch with the proposed changes. review
modernize_uuid.patch serhiy.storchaka,2014-08-04 08:09 review
Messages (10)
msg224671 - (view) Author: Kevin London (kevinlondon) * Date: 2014-08-04 02:05
Generating the byte representation of a UUID object can be a little faster by using binascii's unhexlify on the hex value of the UUID object. In my testing, I saw about a 5.5x speed increase with the attached changes. Here are a set of benchmarks that I ran, which are inspired by Wang Chun's benchmarks on http://bugs.python.org/issue5885: https://gist.github.com/kevinlondon/d3bb32d5a784f78731fa My times: kevin$ python uuid_benchmark.py 100000 Original Average: 8.049 microseconds Updated Average: 1.447 microseconds I re-ran all of the tests with the patched uuid module and they passed. Here's my patchcheck output as well: kevin$ make patchcheck ./python.exe ./Tools/scripts/patchcheck.py Getting the list of files that have been added/changed ... 1 file Fixing whitespace ... 0 files Fixing C file whitespace ... 0 files Fixing docs whitespace ... 0 files Docs modified ... NO Misc/ACKS updated ... NO Misc/NEWS updated ... NO configure regenerated ... not needed pyconfig.h.in regenerated ... not needed Thanks!
msg224672 - (view) Author: Alex Gaynor (alex) * (Python committer) Date: 2014-08-04 02:10
`self.int.to_bytes(16, byteorder='big')` looks to be even faster (about 3x on my machine)
msg224673 - (view) Author: Alex Gaynor (alex) * (Python committer) Date: 2014-08-04 02:10
What I said only applies to the Python3 version of this patch. Thanks for submitting this.
msg224676 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2014-08-04 03:26
I also like the way the patch cleans-up the code.
msg224697 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-08-04 08:09
If such changes are acceptable, here is a part of my large patch fo modernizing stdlib sources. Some microbenchmarks: $ ./python -m timeit -s "from uuid import NAMESPACE_DNS as u" -- "u.bytes" $ ./python -m timeit -s "from uuid import NAMESPACE_DNS as u" -- "u.bytes_le" $ ./python -m timeit -s "from uuid import UUID" -- "UUID(bytes_le=b'abcdefghijklmnop')" Before patch: 10000 loops, best of 3: 66.9 usec per loop 10000 loops, best of 3: 102 usec per loop 10000 loops, best of 3: 65.2 usec per loop After patch: 100000 loops, best of 3: 3.98 usec per loop 100000 loops, best of 3: 10.8 usec per loop 10000 loops, best of 3: 32.1 usec per loop
msg224700 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-08-04 08:28
Just noticed that this patch also fixes a bug. When os.popen() fails in _ipconfig_getnode(), pipe is not set, and then NameError is raised in the finally branch.
msg226498 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-09-06 17:36
Alex, Raymond, could you please make a review of my patch?
msg226499 - (view) Author: Alex Gaynor (alex) * (Python committer) Date: 2014-09-06 17:55
Patch looks good to me.
msg226506 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-09-06 19:21
New changeset f7b5038d3102 by Serhiy Storchaka in branch 'default': Issue #22131: Modernized the code of the uuid module. http://hg.python.org/cpython/rev/f7b5038d3102 New changeset d8c6b15a2ae3 by Serhiy Storchaka in branch '2.7': Issue #22131: Fixed a bug in handling an error occured during reading from http://hg.python.org/cpython/rev/d8c6b15a2ae3 New changeset 8a61a287776d by Serhiy Storchaka in branch '3.4': Issue #22131: Fixed a bug in handling an error occured during reading from http://hg.python.org/cpython/rev/8a61a287776d
msg226507 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-09-06 19:51
Thank you Alex.
History
Date User Action Args
2022-04-11 14:58:06 admin set github: 66329
2014-09-06 19:51:21 serhiy.storchaka set status: open -> closedmessages: + assignee: serhiy.storchakaresolution: fixedstage: patch review -> resolved
2014-09-06 19:21:25 python-dev set nosy: + python-devmessages: +
2014-09-06 17:55:03 alex set messages: +
2014-09-06 17:36:48 serhiy.storchaka set messages: +
2014-08-04 13:45:11 pitrou set stage: patch reviewversions: - Python 2.7
2014-08-04 12:14:02 ronaldoussoren set assignee: ronaldoussoren -> (no value)components: - macOSnosy: - ronaldoussoren
2014-08-04 08:28:50 serhiy.storchaka set messages: +
2014-08-04 08:09:00 serhiy.storchaka set files: + modernize_uuid.patchnosy: + serhiy.storchakamessages: +
2014-08-04 03:26:45 rhettinger set nosy: + rhettingermessages: +
2014-08-04 02:11:03 alex set versions: + Python 3.5
2014-08-04 02:10:58 alex set messages: +
2014-08-04 02:10:00 alex set nosy: + alexmessages: +
2014-08-04 02:05:56 kevinlondon create