This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author serhiy.storchaka
Recipients Guido.van.Rossum, Mark.Shannon, gvanrossum, iritkatriel, methane, rhettinger, serhiy.storchaka, terry.reedy
Date 2021-10-02.15:30:08
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1633188609.05.0.481765018602.issue36521@roundup.psfhosted.org>
In-reply-to
Content
> I'm confused by your phrase "take data" -- do you mean remove these? Or wht do you propose we do with them?

I thought that function's name and qualname are set in the code that creates a function instead of copying from the code object. Similarly as what Inada-san propose for docstring. Perhaps it was in the past. Also, the documentation tells that annotations is a tuple of strings, so it should be known at the compile time. I propose to make it an attribute of the code object and copy to the function object when create a function. It saves a LOAD_CONST.

> Smaller, maybe. Measurably faster? Can you demonstrate that with a patch?

$ ./python -m pyperf timeit --duplicate=100  "def f(x: 'int', y: 'str') -> 'float': pass"
Mean +- std dev: 64.6 ns +- 4.2 ns
$ ./python -m pyperf timeit --duplicate=100  "def f(x, y): pass"
Mean +- std dev: 59.5 ns +- 2.4 ns

The difference 5.1 ns is the cost of additional LOAD_CONST. It is around 8% (but can be 12% or 2%). The cost of setting docstring externally will be the same.

> Oh, what do you mean exactly by "local functions" -- is that any function, or only a function nested inside another function?

Global functions and methods of global classes created at import time and only once. But functions nested inside another function are created every time when the external function is created, and they can even be created in a loop. It is a tiny cost, by why make it larger?
History
Date User Action Args
2021-10-02 15:30:09serhiy.storchakasetrecipients: + serhiy.storchaka, gvanrossum, rhettinger, terry.reedy, methane, Mark.Shannon, Guido.van.Rossum, iritkatriel
2021-10-02 15:30:09serhiy.storchakasetmessageid: <1633188609.05.0.481765018602.issue36521@roundup.psfhosted.org>
2021-10-02 15:30:09serhiy.storchakalinkissue36521 messages
2021-10-02 15:30:08serhiy.storchakacreate