[issue36521] Consider removing docstrings from co_consts in code objects

Inada Naoki report at bugs.python.org
Mon Aug 30 22:52:22 EDT 2021


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

I grepped top 5000 downloaded packages and I can not find any real use of PyFunction_New(WithQualName).
So I don't know what is current workflow of PyFunction_New.

My current wip implementation adds new API (e.g. PyFunction_NewWithDoc()).
Old API keep using co_consts[0] for docstring for backward compatibility.

Adding code.co_doc is not free.

* All code objects have one additional pointer. So it eats memory.
* Unmarshal need to call `r_object()` for all code objects. So it increase startup time.

Note that code objects is not for only functions. Class, modules, lambdas, comprehensions uses code objects without docstring.
And if PEP 649 is accepted, even function annotations will use code objects. It will double the number of code objects in the highly annotated source files.

----------

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


More information about the Python-bugs-list mailing list