On Donnerstag, 4. Oktober 2018 16:52:13 CEST Alberto Planas Dominguez wrote:
Hi,
As you know the Python packages are collecting the pyc/pyo precompiled binaries inside the RPM. This is mostly a good idea, as makes the first execution of the Python code faster, as is skipped the stage where the interpreter compile the .py code.
But this also makes the Python stack a bit fat. Most of the time this is not a problem, but things are changing. We have JeOS and MicroOS, both minimal images (build with different goals and technology) that search for be small and slim. But we want to include a bit of Python in there, like salt-minion or cloud-init. And now the relative size of Python is evident.
Some different ideas how to reduce the footprint: 1. make sure your stack is completely migrated to python3 2. make sure you ship just a single optimization level [1] 3. enable FS level compression, e.g. with btrfs For (2.), on TW python3-base e.g. ships three bytecode files per source file - unoptimized, level 1 and level 2: --- $> du -b /usr/lib64/python3.6/xml/dom/{,__pycache__}/minidom* 66819 /usr/lib64/python3.6/xml/dom//minidom.py 55738 /usr/lib64/python3.6/xml/dom/__pycache__/minidom.cpython-36.opt-1.pyc 54164 /usr/lib64/python3.6/xml/dom/__pycache__/minidom.cpython-36.opt-2.pyc 55840 /usr/lib64/python3.6/xml/dom/__pycache__/minidom.cpython-36.pyc --- For python, optimized just means stripping "assert"s (opt-1) + stripping docstrings (opt-2). As long as you don't execute python with the "-O" option - explicitly or as part of the she-bang - the opt-1 and opt-2 files are completely ignored. You can verify this e.g. with: $> strace -efile -o'|grep minidom.' python3 -O -c 'import xml.dom.minidom' stat("/usr/lib64/python3.6/xml/dom/minidom.py", {st_mode=S_IFREG|0644, st_size=66819, ...}) = 0 openat(AT_FDCWD, "/usr/lib64/python3.6/xml/dom/__pycache__/ minidom.cpython-36.opt-1.pyc", O_RDONLY|O_CLOEXEC) = 3 For (3.), compressing with zstd level 6, python sources can be compressed about 3 times and bytecode still by more than 2. Kind regards, Stefan-- To unsubscribe, e-mail: opensuse-packaging+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-packaging+owner@opensuse.org