-
-
Notifications
You must be signed in to change notification settings - Fork 34.4k
.pyc files are larger than they need to be #99554
Copy link
Copy link
Closed
Labels
3.12only security fixesonly security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
Metadata
Metadata
Assignees
Labels
3.12only security fixesonly security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
Python 3.11 made
.pycfiles 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:
CACHEentries). This results in serialized bytecode that is ~66% smaller than 3.11.EXTENDED_ARGs andCACHEs 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.pycfiles 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,
.pycfiles 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
marshalbytecode more efficiently #99555