mirror of
https://github.com/python/cpython.git
synced 2025-07-19 01:05:26 +00:00
bpo-45020: Freeze some of the modules imported during startup. (gh-28335)
Doing this provides significant performance gains for runtime startup (~15% with all the imported modules frozen). We don't yet freeze all the imported modules because there are a few hiccups in the build systems we need to sort out first. (See bpo-45186 and bpo-45188.) Note that in PR GH-28320 we added a command-line flag (-X frozen_modules=[on|off]) that allows users to opt out of (or into) using frozen modules. The default is still "off" but we will change it to "on" as soon as we can do it in a way that does not cause contributors pain. https://bugs.python.org/issue45020
This commit is contained in:
parent
1a9ef57985
commit
cbeb819710
19 changed files with 6879 additions and 30 deletions
|
@ -30,6 +30,9 @@ PCBUILD_PROJECT = os.path.join(ROOT_DIR, 'PCbuild', '_freeze_module.vcxproj')
|
|||
PCBUILD_FILTERS = os.path.join(ROOT_DIR, 'PCbuild', '_freeze_module.vcxproj.filters')
|
||||
TEST_CTYPES = os.path.join(STDLIB_DIR, 'ctypes', 'test', 'test_values.py')
|
||||
|
||||
|
||||
OS_PATH = 'ntpath' if os.name == 'nt' else 'posixpath'
|
||||
|
||||
# These are modules that get frozen.
|
||||
FROZEN = [
|
||||
# See parse_frozen_spec() for the format.
|
||||
|
@ -43,6 +46,28 @@ FROZEN = [
|
|||
# on a builtin zip file instead of a filesystem.
|
||||
'zipimport',
|
||||
]),
|
||||
('stdlib', [
|
||||
# For the moment we skip codecs, encodings.*, os, and site.
|
||||
# These modules have different generated files depending on
|
||||
# if a debug or non-debug build. (See bpo-45186 and bpo-45188.)
|
||||
# without site (python -S)
|
||||
'abc',
|
||||
#'codecs',
|
||||
# '<encodings.*>',
|
||||
'io',
|
||||
# with site
|
||||
'_collections_abc',
|
||||
'_sitebuiltins',
|
||||
'genericpath',
|
||||
'ntpath',
|
||||
'posixpath',
|
||||
# We must explicitly mark os.path as a frozen module
|
||||
# even though it will never be imported.
|
||||
#f'{OS_PATH} : os.path',
|
||||
#'os',
|
||||
#'site',
|
||||
'stat',
|
||||
]),
|
||||
('Test module', [
|
||||
'hello : __hello__ = ' + os.path.join(TOOLS_DIR, 'freeze', 'flag.py'),
|
||||
'hello : <__phello__>',
|
||||
|
@ -486,9 +511,9 @@ def regen_makefile(modules):
|
|||
# Note that we freeze the module to the target .h file
|
||||
# instead of going through an intermediate file like we used to.
|
||||
rules.append(f'{header}: Programs/_freeze_module {pyfile}')
|
||||
rules.append(f'\t$(srcdir)/Programs/_freeze_module {src.frozenid} \\')
|
||||
rules.append(f'\t\t$(srcdir)/{pyfile} \\')
|
||||
rules.append(f'\t\t$(srcdir)/{header}')
|
||||
rules.append(
|
||||
(f'\t$(srcdir)/Programs/_freeze_module {src.frozenid} '
|
||||
f'$(srcdir)/{pyfile} $(srcdir)/{header}'))
|
||||
rules.append('')
|
||||
|
||||
frozenfiles[-1] = frozenfiles[-1].rstrip(" \\")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue