[issue45556] uuid.uuid4() fast optimization

2021-10-21 Thread Christian Heimes


Christian Heimes  added the comment:

We use os.urandom() because it is backed by a cryptographicly secure random 
number generator. The random module uses a non-secure RNG. While RFC 4122 does 
not mandate a CSRPNG, application often rely on unpredictable UUIDs. 
Correctness and security is more important here than performance.

If you need a faster uuid4 implementation, then you can role your own with a 
couple of lines of code:

import random
from uuid import UUID

def uuid4_fast():
return UUID(int=random.getrandbits(128), version=4)

--
nosy: +christian.heimes
resolution:  -> rejected
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45556] uuid.uuid4() fast optimization

2021-10-21 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

random.getrandbits() is cryptographically weaker than os.urandom().

--
nosy: +rhettinger, serhiy.storchaka

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45556] uuid.uuid4() fast optimization

2021-10-21 Thread Mosquito


Change by Mosquito :


--
pull_requests: +27402
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/29125

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45556] uuid.uuid4() fast optimization

2021-10-21 Thread Mosquito

New submission from Mosquito :

I does a small experiment, and found out that if you generate UUID4 with int 
instead of sequence of bytes, then the generation of UUID4 occurs up to three 
times faster.

.. code-block: python

import random
import uuid

print("uuid.uuid4()")
%timeit uuid.uuid4()
# 5.49 µs ± 120 ns per loop (mean ± std. dev. of 7 runs, 10 loops each)

print("uuid.UUID(int=random.getrandbits(128), version=4)")
%timeit uuid.UUID(int=random.getrandbits(128), version=4)
# 2.58 µs ± 94.5 ns per loop (mean ± std. dev. of 7 runs, 10 loops each)


I have already made fixes to my fork on GH, tell me, will it be useful to 
someone else besides me?

--
components: Library (Lib)
files: 0001-Generating-uuid.uuid4-up-to-three-times-faster.patch
keywords: patch
messages: 404607
nosy: mosquito
priority: normal
severity: normal
status: open
title: uuid.uuid4() fast optimization
type: performance
versions: Python 3.10
Added file: 
https://bugs.python.org/file50381/0001-Generating-uuid.uuid4-up-to-three-times-faster.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com