.pyc
files are larger than they need to be
#99554
Labels
3.12
interpreter-core
(Objects, Python, Grammar, and Parser dirs)
performance
Performance or resource usage
stdlib
Python modules in the Lib dir
brandtbucher commentedNov 17, 2022
•
edited by bedevere-bot
Python 3.11 made
.pyc
files almost twice as large. There are two main reasons for this:(Note that these effects compound each other, since longer bytecode means more location entries.)
However, there is low-hanging fruit for improving this situation in 3.12:
CACHE
entries). This results in serialized bytecode that is ~66% smaller than 3.11.EXTENDED_ARG
s andCACHE
s corresponding to a single instruction, but with slight changes the compiler can use the same mechanism to share location table entries between adjacent instructions. This is a double-win, since it not only makes.pyc
files smaller, but also shrinks the memory footprint of all code objects in the process. Experiments show that this makes location tables ~33% smaller than 3.11.When both of these optimizations are applied,
.pyc
files become ~33% smaller than 3.11. This is only ~33% larger than 3.10, despite all of the rich new debugging information present.Linked PRs
marshal
bytecode more efficiently #99555The text was updated successfully, but these errors were encountered: