◐ Shell
clean mode source ↗

Message 176012 - Python tracker

Here is the statistics for all pyc-files (not only in Lib/__pycache__). This includes encoding tables and tests. I count also memory usage for some types (for tuples shared size is estimated upper limit).

type             count %          size   shared %

UNICODE         622812 58%    26105085 14885090 57%
TUPLE           224214 21%     8184848  3498300 43%
STRING           90992 8.4%    6931342   832224 12%
INT              52087 4.8%     715400    58666 8.2%
CODE             42147 3.9%    2865996        0 0%
NONE             39777 3.7%  
BINARY_FLOAT      3120 0.29% 
TRUE              2363 0.22% 
FALSE             1976 0.18% 
LONG              1012 0.094%
ELLIPSIS           528 0.049%
BINARY_COMPLEX     465 0.043%
FROZENSET           24 0.0022%

Total          1081517 100%   44802671 19274280 ~43%


Yet some statistics. If we import all standard modules, we can save using object sharing 2.3 MB of total 4.6 MB (50%) memory size for unicode objects, up to 0.47 MB of 1.25 MB for tuples (approximate upper limit), 84 KB of 117 KB (7%) for bytes objects, and only 2 KB of 101 KB for integers (most integers already interned). None of code objects can be shared (because code object contains almost unique first line number).

Therefore there is a sense to share unicode objects, tuples, and may be bytes objects. Most integers (in range -5..257) already interned. None of code objects can be shared (because code object contains almost unique first line number). Floats, complexes and frozensets unlikely save much of memory.