mirror of
https://github.com/python/cpython.git
synced 2025-10-17 04:08:28 +00:00
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
This commit is contained in:
parent
9b4e3d94a5
commit
bf95ff91f2
9 changed files with 87 additions and 84 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue