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:
Eric Snow 2021-09-15 10:19:30 -06:00 committed by GitHub
parent 1a9ef57985
commit cbeb819710
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 6879 additions and 30 deletions

View file

@ -41,6 +41,14 @@
#include "frozen_modules/importlib__bootstrap.h"
#include "frozen_modules/importlib__bootstrap_external.h"
#include "frozen_modules/zipimport.h"
#include "frozen_modules/abc.h"
#include "frozen_modules/io.h"
#include "frozen_modules/_collections_abc.h"
#include "frozen_modules/_sitebuiltins.h"
#include "frozen_modules/genericpath.h"
#include "frozen_modules/ntpath.h"
#include "frozen_modules/posixpath.h"
#include "frozen_modules/stat.h"
#include "frozen_modules/hello.h"
/* End includes */
@ -54,6 +62,17 @@ static const struct _frozen _PyImport_FrozenModules[] = {
(int)sizeof(_Py_M__importlib__bootstrap_external)},
{"zipimport", _Py_M__zipimport, (int)sizeof(_Py_M__zipimport)},
/* stdlib */
{"abc", _Py_M__abc, (int)sizeof(_Py_M__abc)},
{"io", _Py_M__io, (int)sizeof(_Py_M__io)},
{"_collections_abc", _Py_M___collections_abc,
(int)sizeof(_Py_M___collections_abc)},
{"_sitebuiltins", _Py_M___sitebuiltins, (int)sizeof(_Py_M___sitebuiltins)},
{"genericpath", _Py_M__genericpath, (int)sizeof(_Py_M__genericpath)},
{"ntpath", _Py_M__ntpath, (int)sizeof(_Py_M__ntpath)},
{"posixpath", _Py_M__posixpath, (int)sizeof(_Py_M__posixpath)},
{"stat", _Py_M__stat, (int)sizeof(_Py_M__stat)},
/* Test module */
{"__hello__", _Py_M__hello, (int)sizeof(_Py_M__hello)},
{"__phello__", _Py_M__hello, -(int)sizeof(_Py_M__hello)},