Title: Implement CALL_FUNCTION adaptive interpreter optimizations
Type: performance Stage: patch review
Components: Versions: Python 3.11
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Mark.Shannon, kj
Priority: normal Keywords: patch

Created on 2021-06-28 14:22 by kj, last changed 2021-06-28 14:33 by kj.

Pull Requests
URL Status Linked Edit
PR 26934 open kj, 2021-06-28 14:33
Messages (1)
msg396639 - (view) Author: Ken Jin (kj) * (Python committer) Date: 2021-06-28 14:22
CALL_FUNCTION can be specialized. Copying from Mark's comments

There are a number of specializations of CALL_FUNCTION that make sense:

1. Calls to a Python function where the arguments and parameters match exactly.
2. Calls to a Python function with keyword arguments, or defaults, when the argument shuffle can be pre-computed.
3. Calls to builtin functions.
4. Calls to specific builtin functions, specifically len and instance.
5. Calls to type with a single argument.
6. Instantiation of a "normal" class, that is a class that does not redefine __new__ and whose metaclass is type.

I've prepared a PR that should speed up non-keyword calls to PyCFunction. It covers specializations 3 and 4. Stable pyperf microbenchmarks show 5-15% less call overhead for some PyCFunctions. Please see for the benchmark script and results.

This issue is also tied to issue44207 (Add a version number to Python functions) which will be required for specializations 1 and 2.
Date User Action Args
2021-06-28 14:33:06kjsetkeywords: + patch
stage: patch review
pull_requests: + pull_request25503
2021-06-28 14:22:18kjcreate