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 andpython -OO
(no LTO) build and a dedicatedUUID.from_int
constructor:The above benchmarks keep constants as is since constant folding would remove the inefficiency of recomputing
1 << const
everytime. With a hardcoded1 << const
, the numbers are (almost) identical.I did not change the 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).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: