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 Mark.Shannon
Recipients Mark.Shannon, kj
Date 2022-01-26.11:11:01
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1643195461.79.0.974638487251.issue46533@roundup.psfhosted.org>
In-reply-to
Content
For classmethods, I expect the savings to come from not creating a bound-method and from better specialization of the following call.

classmethod case:

>>> class C:
...     @classmethod
...     def m(*args):
...          pass
... 
>>> C.m
<bound method C.m of <class '__main__.C'>>
>>> C().m
<bound method C.m of <class '__main__.C'>>

So, without specialization LOAD_METHOD "m" has the following stack effect (with `x = C()`):
x -> NULL <bound method>
C -> NULL <bound method>
With specialization:
x -> C <function>
C -> C <function>

For static methods the saving is less as there is no change in stack effect, but we do save the lookup, and we can reuse existing bytecodes.


Neither classmethod or staticmethod should have Py_TPFLAGS_METHOD_DESCRIPTOR set, as they have different semantics.
History
Date User Action Args
2022-01-26 11:11:01Mark.Shannonsetrecipients: + Mark.Shannon, kj
2022-01-26 11:11:01Mark.Shannonsetmessageid: <1643195461.79.0.974638487251.issue46533@roundup.psfhosted.org>
2022-01-26 11:11:01Mark.Shannonlinkissue46533 messages
2022-01-26 11:11:01Mark.Shannoncreate