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
abs_paths() in site.py is slow #73778
Comments
abs_paths() is the another most slow parts of site module. But before trying it, is abs_paths() really needed for now? Here is profile output. sysconfig dependency is removed by bpo-29585 patch, and pstat is modified Ordered by: cumulative time ncalls tottime percall cumtime percall filename:lineno(function) |
path normalization was added by |
https://github.com/python/cpython/blob/master/Lib/importlib/_bootstrap_external.py#L1089-L1095 While '' in sys.path, it is converted to |
$ python2 -S
Python 2.7.12+ (default, Sep 17 2016, 12:08:02)
[GCC 6.2.0 20160914] on linux2
>>> import x
>>> x.__file__
'x.py'
$ python3 -S
Python 3.6.0 (default, Dec 30 2016, 20:49:54)
[GCC 6.2.0 20161005] on linux
>>> import x
>>> x.__file__
'/home/inada-n/x.py' I think we can remove I added all import experts to nosy list. |
Aye, I agree it should be redundant now - import system should always be making __file__ and __cached__ absolutely at import time these days. So +1 for dropping this from 3.7 and getting a bit of startup time back. |
CI failure indicating it isn't redundant, but could still potentially be made faster since non-absolute paths should be relatively rare now: ====================================================================== FAIL: test_s_option (test.test_site.HelperFunctionsTests) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/travis/build/python/cpython/Lib/test/test_site.py", line 173, in test_s_option self.assertIn(usersite, sys.path) AssertionError: '/home/travis/.local/lib/python3.7/site-packages' not found in ['', '/usr/local/lib/python37.zip', '/home/travis/build/python/cpython/Lib', '/home/travis/build/python/cpython/build/lib.linux-x86_64-3.7-pydebug'] ====================================================================== FAIL: test_abs_paths (test.test_site.ImportSideEffectTests) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/travis/build/python/cpython/Lib/test/test_site.py", line 365, in test_abs_paths .format(os__file__.decode('ascii'))) AssertionError: False is not true : expected absolute path, got ../../Lib/os.py ---------------------------------------------------------------------- |
Note that "os" doesn't get imported normally, it gets injected as part of the importlib bootstrapping process (since _bootstrap_external.py needs the os module in order to work). |
I got it. I updated PR 167 to call abs_paths() only if removeduppaths() modified sys.path. But because duplicated paths are rare too, I think this approach is practical enough. |
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: