Author nascheme
Recipients nascheme
Date 2021-06-07.02:41:46
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Note: This is a proof of concept and not ready for merging as is.

This is based on 'frozen_modules' from Jeethu Rao <>, via Larry Hastings.  Larry's git branch was:


- Compile Python as normal
- Run "make regen-freeze-startup" to re-generate Python/frozenmodules_code.c
- Compile Python a second time

Changes from Larry's branch:

- Move static C code generation tool to Tools/freeze2
- Move _serializer to Modules
- Rebase on Python 3.10.0b1
- determine startup modules by running sys.executable
- use importlib.util.find_spec() to get code objects
- fix ref-counting when setting __path__
- put static frozen modules in frozen_code_objects dict
- reduce set of "bad" modules as it seems only _collections_abc needs
- fix the is_frozen_package() and is_frozen() functions to find
  static frozen code

It's not passing all unit tests yet but I'm somewhat hopeful there are no deep problems.  Porting the changes from 3.6 to 3.8 and then to 3.10 was not too horrible.  There was a few changes to PyGC_Head, to the PyCodeObject structure and to the runtime initialization process.  That gives me some hope that it wouldn't be too burdensome to maintain this in the long-term.  Mostly it would be updating _serialize.c to keep up with PyCodeObject changes.

Based on benchmarking with 3.8, this gives a decent speedup for startup of a trival program, e.g. python -c "True".  I measure it as taking 76% of the time.  The savings are mostly in marshal.c but there is also some importlib/filesystem overhead that's removed.
Date User Action Args
2021-06-07 02:41:46naschemesetrecipients: + nascheme
2021-06-07 02:41:46naschemesetmessageid: <>
2021-06-07 02:41:46naschemelinkissue44331 messages
2021-06-07 02:41:46naschemecreate