From 30dcf7855fab86bbc824f96da5a6035b9da09562 Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Thu, 16 Feb 2017 17:45:38 +0900 Subject: [PATCH] Optimize startup time when user site is disabled. Skip getusersitepackages() call and indirect import of sysconfig module. Roughly, `python -s -c '42'` becomes 14ms from 15ms. --- Lib/site.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Lib/site.py b/Lib/site.py index 0fc92009e19af3..b59f352588ccb6 100644 --- a/Lib/site.py +++ b/Lib/site.py @@ -124,7 +124,7 @@ def removeduppaths(): # if they only differ in case); turn relative paths into absolute # paths. dir, dircase = makepath(dir) - if not dircase in known_paths: + if dircase not in known_paths: L.append(dir) known_paths.add(dircase) sys.path[:] = L @@ -279,9 +279,11 @@ def addusersitepackages(known_paths): """ # get the per user site-package path # this call will also make sure USER_BASE and USER_SITE are set - user_site = getusersitepackages() + if not ENABLE_USER_SITE: + return known_paths - if ENABLE_USER_SITE and os.path.isdir(user_site): + user_site = getusersitepackages() + if os.path.isdir(user_site): addsitedir(user_site, known_paths) return known_paths