aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Python/import.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2021-11-10 18:01:53 -0800
committerGitHub <noreply@github.com>2021-11-10 18:01:53 -0800
commit1cbaa505d007e11c4a1f0d2073d72b6c02c7147c (patch)
tree671391d64df20ebcf2960fae83030e61f5527aa3 /Python/import.c
parentfc9b62281931da8d20f85d5ed44cfc24f068d3f4 (diff)
downloadcpython-1cbaa505d007e11c4a1f0d2073d72b6c02c7147c.tar.gz
cpython-1cbaa505d007e11c4a1f0d2073d72b6c02c7147c.zip
bpo-45696: Deep-freeze selected modules (GH-29118)
This gains 10% or more in startup time for `python -c pass` on UNIX-ish systems. The Makefile.pre.in generating code builds on Eric's work for bpo-45020, but the .c file generator is new. Windows version TBD.
Diffstat (limited to 'Python/import.c')
-rw-r--r--Python/import.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/Python/import.c b/Python/import.c
index cdcb903c882..225fbf43a30 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -1262,6 +1262,7 @@ look_up_frozen(const char *name)
struct frozen_info {
PyObject *nameobj;
const char *data;
+ PyObject *(*get_code)(void);
Py_ssize_t size;
bool is_package;
bool is_alias;
@@ -1295,6 +1296,7 @@ find_frozen(PyObject *nameobj, struct frozen_info *info)
if (info != NULL) {
info->nameobj = nameobj; // borrowed
info->data = (const char *)p->code;
+ info->get_code = p->get_code;
info->size = p->size < 0 ? -(p->size) : p->size;
info->is_package = p->size < 0 ? true : false;
info->origname = name;
@@ -1316,6 +1318,11 @@ find_frozen(PyObject *nameobj, struct frozen_info *info)
static PyObject *
unmarshal_frozen_code(struct frozen_info *info)
{
+ if (info->get_code) {
+ PyObject *code = info->get_code();
+ assert(code != NULL);
+ return code;
+ }
PyObject *co = PyMarshal_ReadObjectFromString(info->data, info->size);
if (co == NULL) {
/* Does not contain executable code. */