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.

classification
Title: Speed up classmethod calls via LOAD_METHOD
Type: performance Stage: patch review
Components: Interpreter Core Versions: Python 3.11
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: corona10, kj
Priority: normal Keywords: patch

Created on 2021-09-26 16:29 by kj, last changed 2022-04-11 14:59 by admin.

Pull Requests
URL Status Linked Edit
PR 28572 open kj, 2021-09-27 10:06
Messages (1)
msg402668 - (view) Author: Ken Jin (kj) * (Python committer) Date: 2021-09-26 16:29
LOAD_METHOD + CALL_METHOD currently doesn't work for Python @classmethod and C classmethod (METH_CLASS). They still create bound classmethods which are fairly expensive.

I propose supporting classmethods. I have an implementation for C classmethods. It passes most of the test suite, and I've also got it to play along with PEP 659 specialization.

Some numbers from Windows release build (PGO build will likely be less favorable):

python.exe -m timeit "int.from_bytes(b'')"
Main:
2000000 loops, best of 5: 107 nsec per loop
Patched:
5000000 loops, best of 5: 72.4 nsec per loop

Funnily enough, `(1).from_bytes()` still needs a bound classmethod, but I think people usually use the other form.

A toy PR will be up for review. I will then split the change into two parts (one for _PyObject_GetMethod changes, another for PEP 659 specialization) to help decide if the maintenance-perf ratio is worth it.
History
Date User Action Args
2022-04-11 14:59:50adminsetgithub: 89458
2021-09-29 12:47:50corona10setnosy: + corona10
2021-09-27 14:28:29kjsettitle: _PyObject_GetMethod/LOAD_METHOD for C classmethods -> Speed up classmethod calls via LOAD_METHOD
2021-09-27 10:06:03kjsetkeywords: + patch
stage: patch review
pull_requests: + pull_request26961
2021-09-26 16:29:41kjcreate