[issue36521] Consider removing docstrings from co_consts in code objects
Inada Naoki
report at bugs.python.org
Sat Oct 2 22:10:24 EDT 2021
Inada Naoki <songofacandy at gmail.com> added the comment:
> 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.
I don't have bare metal machine for now so I don't know why annotation is so slow. But cost of setting docstring is lighter.
```
# main branch
$ cpython/release/bin/pyperf timeit --duplicate=100 "def f():
> 'docstring'"
.....................
Mean +- std dev: 61.5 ns +- 1.3 ns
# https://github.com/methane/cpython/pull/37
$ load-none-remove-docstring/release/bin/pyperf timeit --duplicate=100 "def f():
> 'docstring'"
.....................
Mean +- std dev: 62.9 ns +- 1.5 ns
$ load-none-remove-docstring/release/bin/pyperf timeit --duplicate=100 "def f(x: 'int', y: 'str') -> 'float': pass"
.....................
Mean +- std dev: 65.1 ns +- 4.3 ns
$ load-none-remove-docstring/release/bin/pyperf timeit --duplicate=100 "def f(x: 'int', y: 'str') -> 'float': 'docstring'"
.....................
Mean +- std dev: 66.3 ns +- 2.6 ns
$ load-none-remove-docstring/release/bin/pyperf timeit --duplicate=100 "def f(x: 'int', y: 'str') -> 'float': 'docstring'
> f(None,None)"
.....................
Mean +- std dev: 131 ns +- 6 ns
```
So overhead is around 2%. And this 2% is problem only for "creating function with annotation, without docstring, never called, in loop" situation.
In regular situation, this overhead will be negligible.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue36521>
_______________________________________
More information about the Python-bugs-list
mailing list