summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShantanu <12621235+hauntsaninja@users.noreply.github.com>2024-03-06 22:39:43 (GMT)
committerGitHub <noreply@github.com>2024-03-06 22:39:43 (GMT)
commit68b8ffff8c4b20d2f46b708b1a7906377ecc255f (patch)
tree489afdf2dd9810a93ba4eb9ad182e1ac38193f8d
parent0876b921b28bb14e3fa61b188e52fc9b4c77cb1a (diff)
downloadcpython-68b8ffff8c4b20d2f46b708b1a7906377ecc255f.zip
cpython-68b8ffff8c4b20d2f46b708b1a7906377ecc255f.tar.gz
cpython-68b8ffff8c4b20d2f46b708b1a7906377ecc255f.tar.bz2
gh-109653: Reduce import overhead of uuid module on Linux (#115160)
This follows in the footsteps of #21586 This speeds up import uuid by about 6ms on Linux. Before: ``` λ hyperfine -w 4 "./python -c 'import uuid'" Benchmark 1: ./python -c 'import uuid' Time (mean ± σ): 20.4 ms ± 0.4 ms [User: 16.7 ms, System: 3.8 ms] Range (min … max): 19.6 ms … 21.8 ms 136 runs ``` After: ``` λ hyperfine -w 4 "./python -c 'import uuid'" Benchmark 1: ./python -c 'import uuid' Time (mean ± σ): 14.5 ms ± 0.3 ms [User: 11.5 ms, System: 3.2 ms] Range (min … max): 13.9 ms … 16.0 ms 175 runs ```
-rw-r--r--Lib/uuid.py5
-rw-r--r--Misc/NEWS.d/next/Documentation/2024-02-08-08-51-37.gh-issue-109653.QHLW4w.rst1
2 files changed, 5 insertions, 1 deletions
diff --git a/Lib/uuid.py b/Lib/uuid.py
index 470bc0d..d4e486d 100644
--- a/Lib/uuid.py
+++ b/Lib/uuid.py
@@ -53,8 +53,11 @@ from enum import Enum, _simple_enum
__author__ = 'Ka-Ping Yee <ping@zesty.ca>'
# The recognized platforms - known behaviors
-if sys.platform in ('win32', 'darwin', 'emscripten', 'wasi'):
+if sys.platform in {'win32', 'darwin', 'emscripten', 'wasi'}:
_AIX = _LINUX = False
+elif sys.platform == 'linux':
+ _LINUX = True
+ _AIX = False
else:
import platform
_platform_system = platform.system()
diff --git a/Misc/NEWS.d/next/Documentation/2024-02-08-08-51-37.gh-issue-109653.QHLW4w.rst b/Misc/NEWS.d/next/Documentation/2024-02-08-08-51-37.gh-issue-109653.QHLW4w.rst
new file mode 100644
index 0000000..97e0c8d
--- /dev/null
+++ b/Misc/NEWS.d/next/Documentation/2024-02-08-08-51-37.gh-issue-109653.QHLW4w.rst
@@ -0,0 +1 @@
+Improve import time of :mod:`uuid` on Linux.