[issue36521] Consider removing docstrings from co_consts in code objects
Inada Naoki
report at bugs.python.org
Thu Sep 30 06:56:31 EDT 2021
Inada Naoki <songofacandy at gmail.com> added the comment:
I used this tool to count co_const size and numbers.
https://github.com/faster-cpython/tools/pull/6
Target is asyncio in the main branch.
main (b34dd58f):
Total: 31 files; 1,068 code objects; 12,741 lines; 39,208 opcodes; 3,880 total size of co_consts; 738 number of co_consts
LOAD_NONE (https://github.com/python/cpython/pull/28376):
Total: 31 files; 1,068 code objects; 12,741 lines; 39,208 opcodes; 3,617 total size of co_consts; 743 number of co_consts
(b) LOAD_NONE + CO_DOCSTRING (b: https://github.com/methane/cpython/pull/36):
Total: 31 files; 1,068 code objects; 12,741 lines; 39,208 opcodes; 3,272 total size of co_consts; 732 number of co_consts
(d) LOAD_NONE + remove docstring from code (d: https://github.com/methane/cpython/pull/37):
Total: 31 files; 1,068 code objects; 12,741 lines; 39,469 opcodes; 3,255 total size of co_consts; 574 number of co_consts
number of co_consts:
main -> (b) = 738 -> 732 (-6, -0.8%)
(b) -> (d) = 732 -> 574 (-158, -21.6%)
total size of co_consts:
main -> (b) = 3880 -> 3272 (-608, -15.7%)
(b) -> (d) = 3272 -> 3255 (-17, -0.5%) (*)
(*) It seems tiny difference. But note that code objects for modules and classes will be released after execution. So (d) will have smaller total size of remaining co_consts after execution.
---
Another target is SQLAlchemy-1.4.25/lib
main (b34dd58f):
Total: 236 files; 11,802 code objects; 179,284 lines; 372,983 opcodes; 46,091 total size of co_consts; 7,979 number of co_consts
LOAD_NONE (https://github.com/python/cpython/pull/28376):
Total: 236 files; 11,802 code objects; 179,284 lines; 372,983 opcodes; 43,272 total size of co_consts; 7,980 number of co_consts
(b) LOAD_NONE + CO_DOCSTRING (b: https://github.com/methane/cpython/pull/36):
Total: 236 files; 11,802 code objects; 179,284 lines; 372,983 opcodes; 39,599 total size of co_consts; 7,833 number of co_consts
(d) LOAD_NONE + remove docstring from code (d: https://github.com/methane/cpython/pull/37):
Total: 236 files; 11,802 code objects; 179,284 lines; 375,396 opcodes; 39,418 total size of co_consts; 6,526 number of co_consts
number of co_consts:
main -> (b) = 7979 -> 7833 (-146, -1.83%)
(b) -> (d) = 7833 -> 6526 (-1307, -16.7%)
total size of co_consts:
main -> (b) = 46091 -> 39599 (-6492, -14.1%)
(b) -> (d) = 39599 -> 39418 (-141, -0.36%)
---
Conclusion: (b) reduces total size of co_consts significantly, and (d) reduces both of total size and number of co_consts significantly.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue36521>
_______________________________________
More information about the Python-bugs-list
mailing list