tell _frozen_importlib to consider bytecode first#248
Merged
jart merged 2 commits intojart:fastpythonfrom Aug 18, 2021
Merged
Conversation
Closed
jart
approved these changes
Aug 18, 2021
Owner
jart
left a comment
There was a problem hiding this comment.
This is very good. Excellent insight on the absolutize btw. We might want to make Python not do that in general, because absolute paths aren't portable. I'm so happy to hear we don't need the __pycache__ subdirectory. I was worried about that one.
jart
pushed a commit
that referenced
this pull request
Aug 19, 2021
ahgamut
added a commit
to ahgamut/cosmopolitan
that referenced
this pull request
Jun 21, 2022
In jart#248 we changed _bootstrap_external to check for bytecode first, and then check for source files when loading in the import process. Now that we have our own meta_path entry, this change can be undone.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In
Lib/importlib/_bootstrap_external.py, I have the interpreter consider theSourcelessFileLoader(ie.pyc) first and only then fall back to theSourceFileLoader. I runfreeze.comto update theimportlib*.incwith this change.(Note: Why not avoid the above change by simply excluding the
.pyfiles to the ZIP store?)the change in
pylifecycle.cis with respect to my comment here: there is a tiny speed benefit to having the C extensions imported earlier.in
python-stdlib.mkall I did was a find-and-replace.We don't have to have to follow PEP 3147:
Lib/X.pydoesn't have to be compiled intoLib/__pycache__/X.cpython-36.pyc, the pycache + version-name-in-extension business matters only if we are mixing.pycfiles from different versions of Python.Since we are within the ZIP store of a Python 3.6 APE, it's highly unlikely there will be a mix of
.pycfiles, so we can stick to the legacy format ofX.pytoX.pyc. This ought to make the Makefile recipe simpler as well.I removed the
#ifinModules/getpath.cand just setmodule_search_pathto a static value. Now thecalculate_pathfunction is skipped entirely; the APE works without issue, so I don't think it is that important.The final change was to make
site.pyskip modifying the location of the zip store, which messed with everything.The sum effect of all these changes:
time python.com -c "2+2"now takes 0.044s