Skip to content

tell _frozen_importlib to consider bytecode first#248

Merged
jart merged 2 commits intojart:fastpythonfrom
ahgamut:fastpython
Aug 18, 2021
Merged

tell _frozen_importlib to consider bytecode first#248
jart merged 2 commits intojart:fastpythonfrom
ahgamut:fastpython

Conversation

@ahgamut
Copy link
Copy Markdown
Collaborator

@ahgamut ahgamut commented Aug 18, 2021

In Lib/importlib/_bootstrap_external.py, I have the interpreter consider the SourcelessFileLoader (ie .pyc) first and only then fall back to the SourceFileLoader. I run freeze.com to update the importlib*.inc with this change.

(Note: Why not avoid the above change by simply excluding the .py files to the ZIP store?)

the change in pylifecycle.c is with respect to my comment here: there is a tiny speed benefit to having the C extensions imported earlier.

in python-stdlib.mk all I did was a find-and-replace.

We don't have to have to follow PEP 3147: Lib/X.py doesn't have to be compiled into Lib/__pycache__/X.cpython-36.pyc, the pycache + version-name-in-extension business matters only if we are mixing .pyc files 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 .pyc files, so we can stick to the legacy format of X.py to X.pyc. This ought to make the Makefile recipe simpler as well.

I removed the #if in Modules/getpath.c and just set module_search_path to a static value. Now the calculate_path function is skipped entirely; the APE works without issue, so I don't think it is that important.

The final change was to make site.py skip 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

@ahgamut ahgamut mentioned this pull request Aug 18, 2021
Copy link
Copy Markdown
Owner

@jart jart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 jart merged commit ace523c into jart:fastpython Aug 18, 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants