Improve performances of uuid.*
functions
#128150
Labels
performance
Performance or resource usage
stdlib
Python modules in the Lib dir
type-feature
A feature request or enhancement
Feature or enhancement
The dedicated UUID constructors (e.g.,
uuid.uuid4()
) generate bytes and pass them to theUUID
constructor. However, the latter performs multiple and redundant checks. We can by-pass those checks since we are actually creating manually the UUID object. Here are the benchmarks for a PGO (no LTO) build and a dedicatedUUID.from_int
constructor:I did not change UUIDv1 generation because I observed that it would be worse in the
uuid.uuid1()
form (but 50% faster when either the node or the clock sequence is given, but this is likely not the usual call form). Previous benchmarks were using non-dedicatedfrom_int
constructor and were as follows:uuid.uuid1()
,v1_with_node
meansuuid.uuid1(node, None)
, andv1_with_clock_seq
meansuuid.uuid(None, clock_seq)
. In other words, this isuuid.uuid1()
with zero or one known parameter.v3-N
andv5-N
meanuuid.uuid3(..., name)
anduuid.uuid5(..., name)
with a N-byte name.v4
andv8
meanuuid.uuid4()
anduuid.uuid8()
respectively.Benchmark script
I'll submit a PR and we can decide what to keep and what to remove for maintainibility purposes. Note that the
uuid
module has been improved a lot performance-wise especially in terms of import time but I believe that constructing UUIDs objects via their dedicated functions.Linked PRs
uuid.uuid*
constructor functions. #128151The text was updated successfully, but these errors were encountered: