summaryrefslogtreecommitdiffstats
path: root/Python/import.c
diff options
context:
space:
mode:
authorKumar Aditya <59607654+kumaraditya303@users.noreply.github.com>2022-02-04 17:57:03 (GMT)
committerGitHub <noreply@github.com>2022-02-04 17:57:03 (GMT)
commitbf95ff91f2c1fc5a57190491f9ccdc63458b089e (patch)
tree859c08ec6a673693121873c09dbacd148e12bb65 /Python/import.c
parent9b4e3d94a5746af093392ed8e977b26fcc1bfd11 (diff)
downloadcpython-bf95ff91f2c1fc5a57190491f9ccdc63458b089e.zip
cpython-bf95ff91f2c1fc5a57190491f9ccdc63458b089e.tar.gz
cpython-bf95ff91f2c1fc5a57190491f9ccdc63458b089e.tar.bz2
bpo-46608: exclude marshalled-frozen data if deep-freezing to save 300 KB space (GH-31074)
This reduces the size of the data segment by **300 KB** of the executable because if the modules are deep-frozen then the marshalled frozen data just wastes space. This was inspired by comment by @gvanrossum in https://github.com/python/cpython/pull/29118#issuecomment-958521863. Note: There is a new option `--deepfreeze-only` in `freeze_modules.py` to change this behavior, it is on be default to save disk space. ```console # du -s ./python before 27892 ./python # du -s ./python after 27524 ./python ``` Automerge-Triggered-By: GH:ericsnowcurrently
Diffstat (limited to 'Python/import.c')
-rw-r--r--Python/import.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/Python/import.c b/Python/import.c
index 51b779c..be60c43 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -1297,13 +1297,21 @@ find_frozen(PyObject *nameobj, struct frozen_info *info)
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->size = p->size;
+ info->is_package = p->is_package;
+ if (p->size < 0) {
+ // backward compatibility with negative size values
+ info->size = -(p->size);
+ info->is_package = true;
+ }
info->origname = name;
info->is_alias = resolve_module_alias(name, _PyImport_FrozenAliases,
&info->origname);
}
-
+ if (p->code == NULL && p->size == 0 && p->get_code != NULL) {
+ /* It is only deepfrozen. */
+ return FROZEN_OKAY;
+ }
if (p->code == NULL) {
/* It is frozen but marked as un-importable. */
return FROZEN_EXCLUDED;
@@ -2224,7 +2232,7 @@ _imp_get_frozen_object_impl(PyObject *module, PyObject *name,
if (info.nameobj == NULL) {
info.nameobj = name;
}
- if (info.size == 0) {
+ if (info.size == 0 && info.get_code == NULL) {
/* Does not contain executable code. */
set_frozen_error(FROZEN_INVALID, name);
return NULL;