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 methane
Recipients Guido.van.Rossum, Mark.Shannon, gvanrossum, iritkatriel, methane, rhettinger, serhiy.storchaka, terry.reedy
Date 2021-10-04.02:03:18
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1633312998.92.0.43011363294.issue36521@roundup.psfhosted.org>
In-reply-to
Content
Lazy filling func.__doc__ has only 3~5% performance gain. And it has small backward incompatibility.

```
>>> def foo(): "foo"
...
>>> def bar(): "bar"
...
>>> bar.__code__ = foo.__code__
>>> bar.__doc__
'foo'  # was 'bar'
```


Note that non-constant docstring (and PEP 649 will) have larger overhead. Some people don't write docstring for private/local functions, but write annotation for code completion and/or type checking.

```
$ load-none-remove-docstring/release/bin/pyperf timeit --duplicate=100 "def f(x: int, y: str) -> float: pass"
.....................
Mean +- std dev: 111 ns +- 2 ns

$ load-none-remove-docstring/release/bin/pyperf timeit --duplicate=100 "def f(x, y): 'doc'"
.....................
Mean +- std dev: 63.9 ns +- 2.1 ns
```

So I think 2~3ns is a "tiny fraction" here.
History
Date User Action Args
2021-10-04 02:03:19methanesetrecipients: + methane, gvanrossum, rhettinger, terry.reedy, Mark.Shannon, serhiy.storchaka, Guido.van.Rossum, iritkatriel
2021-10-04 02:03:18methanesetmessageid: <1633312998.92.0.43011363294.issue36521@roundup.psfhosted.org>
2021-10-04 02:03:18methanelinkissue36521 messages
2021-10-04 02:03:18methanecreate