[issue36521] Consider removing docstrings from co_consts in code objects

Inada Naoki report at bugs.python.org
Sat Oct 2 03:54:20 EDT 2021


Inada Naoki <songofacandy at gmail.com> added the comment:

> For the sqlalchemy example: the saving in co_consts is about 1.6k (200 pointers), but an increase in bytecode size of 2.4k.

Please see number of co_constatns tuples. (d) saved 1307 tuples compared to (b).
`sys.getsizeof(())` is 40 on 64bit machine. So 1307 tuples is 50k bytes. This not saves only memory usage, but also import time too.

Although bytecode size is increased, they are released soon right after importing module because `LOAD_CONST` is in module or class code.

So there is a significant gain overall.

> It’s not clear that LOAD_NONE/LOAD_COMMON_CONST are worth doing. Any way the docstring question is not necessarily related to that.

I combined with LOAD_NONE because this issue and LOAD_NONE/LOAD_COMMON_CONST has synergy.

But I don't combine it in next time.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue36521>
_______________________________________


More information about the Python-bugs-list mailing list