Message403073
> 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. |
|
Date |
User |
Action |
Args |
2021-10-03 02:10:24 | methane | set | recipients:
+ methane, gvanrossum, rhettinger, terry.reedy, Mark.Shannon, serhiy.storchaka, Guido.van.Rossum, iritkatriel |
2021-10-03 02:10:24 | methane | set | messageid: <1633227024.26.0.853167085386.issue36521@roundup.psfhosted.org> |
2021-10-03 02:10:24 | methane | link | issue36521 messages |
2021-10-03 02:10:24 | methane | create | |
|