-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't import re and sysconfig in site.py #63404
Comments
The site module is loaded at every startup. Nowadays it imports the re and the sysconfig modules. The re module is used for venv config parsing and inside sysconfig. sysconfig is loaded to find the location of the user's site-packages directory. Suggestions:
Without re and sysconfig Python would import only 45 instead of 56 modules at startup (tested on Linux). |
The site and sysconfig module are too intermingled to remove the import of sysconfig from the site module. However the sysconfig module doesn't use the re module in most cases anymore. The parsing functions for Makefile and pyconfig.h are only used by distutils. The patch moves "import re" inside three functions. |
Here is a new patch with unit test and patch for the locale module. The locale modules is loaded by the _io module when any standard stream is not connected to a terminal (or so). |
Review posted on Rietveld. |
I accept hacks to speedup Python is the site module, but it becomes more surprising in the locale module. The issue bpo-9548 proposes to a more generic solution for the locale module at startup. -CONFIG_LINE = re.compile(r'^(?P<key>(\w|[-_])+)\s*=\s*(?P<value>.*)\s*$') If you set the constant to None, it's better to remove it completly (or make it private). It's a public variable, someone may try to read it. I don't know why it is public. |
New changeset 406529adf156 by Christian Heimes in branch 'default': |
Thanks for your input! |
New changeset 2cd1b28d1666 by Christian Heimes in branch 'default': |
Christian, the test is failing on Snow Leopard: ====================================================================== Traceback (most recent call last):
File "/Users/buildbot/buildarea/3.x.murray-snowleopard/build/Lib/test/test_site.py", line 435, in test_startup_imports
self.assertFalse(modules.intersection(re_mods))
AssertionError: {'re', 'sre_compile', 'sre_constants', 'sre_parse', '_sre'} is not false http://buildbot.python.org/all/builders/AMD64%20Snow%20Leop%203.x/builds/106/steps/test/logs/stdio |
New changeset a57dfbba91f9 by Christian Heimes in branch 'default': |
So the "import re" comes from _osx_support, _osx_support is imported by sysconfig. |
New changeset 9f6ef09f6492 by Christian Heimes in branch 'default': |
The imports in _osx_support counteract the performance boost. I neither have an OS X machine and nor do I understand the internals of _osx_support. Perhaps somebody else likes to work on the module. |
Please open a separated issue for OS X, this issue can be closed IMO. |
Good point, bpo-19325 |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: