summaryrefslogtreecommitdiffstats
path: root/Tools/freeze
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 /Tools/freeze
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 'Tools/freeze')
-rw-r--r--Tools/freeze/makefreeze.py12
1 files changed, 6 insertions, 6 deletions
diff --git a/Tools/freeze/makefreeze.py b/Tools/freeze/makefreeze.py
index d7d05db..bc5f856 100644
--- a/Tools/freeze/makefreeze.py
+++ b/Tools/freeze/makefreeze.py
@@ -45,19 +45,19 @@ def makefreeze(base, dict, debug=0, entry_point=None, fail_import=()):
print("freezing", mod, "...")
str = marshal.dumps(m.__code__)
size = len(str)
+ is_package = 'false'
if m.__path__:
- # Indicate package by negative size
- size = -size
- done.append((mod, mangled, size))
+ is_package = 'true'
+ done.append((mod, mangled, size, is_package))
writecode(outfp, mangled, str)
if debug:
print("generating table of frozen modules")
with bkfile.open(base + 'frozen.c', 'w') as outfp:
- for mod, mangled, size in done:
+ for mod, mangled, size, _ in done:
outfp.write('extern unsigned char M_%s[];\n' % mangled)
outfp.write(header)
- for mod, mangled, size in done:
- outfp.write('\t{"%s", M_%s, %d},\n' % (mod, mangled, size))
+ for mod, mangled, size, is_package in done:
+ outfp.write('\t{"%s", M_%s, %d, %s},\n' % (mod, mangled, size, is_package))
outfp.write('\n')
# The following modules have a NULL code pointer, indicating
# that the frozen program should not search for them on the host