You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
On my laptop, start Python compiled in debug mode takes 600 ms. Half of this time is spend in the site module. And most of this time is spend in load the sysconfig module, which parse sysconfig.cfg, just to get the user site packages directory.
Attached patch adds a copy of configparser.RawConfigParser, specialized to parse sysconfig.cfg. Using this patch, Python startup is 25% faster (I didn't check in release mode).
The site.getusersitepackages, site.addusersitepackages and co. functions all call one function which makes sure site.USER_SITE is set according to envvars and command-line options; under python -s, addusersitepackages will not add the user site dir to sys.path, but it will cause site.USER_SITE to be set (to False), so that’s why I can’t be sure that your patch does not change behavior. test_site has good coverage for IIRC (just not sure if it covers starting python -s/-S and then importing site, and python -s/-S then import site then call site.main).
I regret that all these site functions are public, now we can’t simplify them to have the setting of site.USER_SITE in only one place.
I'm not really convinced by my patch. It looks like a quick hack. Nick's PEP-432 looks more promising (in speed), simple and safer. So I prefer to close this issue.
Activity
vstinner commentedon Feb 19, 2012
On my laptop, start Python compiled in debug mode takes 600 ms. Half of this time is spend in the site module. And most of this time is spend in load the sysconfig module, which parse sysconfig.cfg, just to get the user site packages directory.
Attached patch adds a copy of configparser.RawConfigParser, specialized to parse sysconfig.cfg. Using this patch, Python startup is 25% faster (I didn't check in release mode).
vstinner commentedon Feb 19, 2012
To speed up python -s, the following patch avoids loading the sysconfig module:
I don't know if this patch is correct.
merwok commentedon Feb 20, 2012
The site.getusersitepackages, site.addusersitepackages and co. functions all call one function which makes sure site.USER_SITE is set according to envvars and command-line options; under python -s, addusersitepackages will not add the user site dir to sys.path, but it will cause site.USER_SITE to be set (to False), so that’s why I can’t be sure that your patch does not change behavior. test_site has good coverage for IIRC (just not sure if it covers starting python -s/-S and then importing site, and python -s/-S then import site then call site.main).
I regret that all these site functions are public, now we can’t simplify them to have the setting of site.USER_SITE in only one place.
vstinner commentedon Feb 21, 2012
Updated patch: continue to simplify the config parser. Using this patch, Python startup is ~20% faster on my computer.
Use http://bugs.python.org/file24447/bench_startup.py to measure startup time.
vstinner commentedon Jan 3, 2013
I'm not really convinced by my patch. It looks like a quick hack. Nick's PEP-432 looks more promising (in speed), simple and safer. So I prefer to close this issue.