classification
Title: Fill func.__doc__ lazily
Type: Stage:
Components: Interpreter Core Versions: Python 3.11
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: corona10, methane, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2021-10-13 02:49 by methane, last changed 2021-10-13 08:40 by serhiy.storchaka.

Pull Requests
URL Status Linked Edit
PR 28704 open methane, 2021-10-13 02:50
Messages (4)
msg403786 - (view) Author: Inada Naoki (methane) * (Python committer) Date: 2021-10-13 02:49
Move setting `func.__doc__` from PyFunction_New() to __doc__ descriptor, for faster function creation.

This issue is spin-off of bpo-36521.
msg403787 - (view) Author: Inada Naoki (methane) * (Python committer) Date: 2021-10-13 02:54
Pros:

Faster (about 3~5%) faster function creation, when function don't have annotations.
When function has annotation, function creation is much slower so performance gain become tiny.

Cons:

Somewhat backward incompatible:

```
>>> def foo(): "foo"
...
>>> def bar(): "bar"
...
>>> bar.__code__ = foo.__code__
>>> bar.__doc__
'foo'  # was 'bar'
```
msg403807 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-10-13 08:31
The behavior difference can be eliminated if make func_set_code() calling func_get_doc().
msg403808 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-10-13 08:40
BTW, I think that we spent on issue36521 much more time (especially your time, Inada-san) than it deserved. In normal case 3~5% would look not impressive. But I do not see any immediate drawbacks of making this change, and I afraid that if we do not make it now we will spend more time on discussing issue36521 and related ideas.
History
Date User Action Args
2021-10-13 08:40:24serhiy.storchakasetmessages: + msg403808
2021-10-13 08:31:58serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg403807
2021-10-13 06:19:39corona10setnosy: + corona10
2021-10-13 02:54:10methanesetmessages: + msg403787
stage: patch review ->
2021-10-13 02:50:15methanesetkeywords: + patch
stage: patch review
pull_requests: + pull_request27206
2021-10-13 02:49:58methanecreate