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: Implement CALL_FUNCTION adaptive interpreter optimizations
Type: performance Stage: patch review
Components: Versions: Python 3.11
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Mark.Shannon, kj, pablogsal, sobolevn, thesamesam
Priority: normal Keywords: patch

Created on 2021-06-28 14:22 by kj, last changed 2022-04-11 14:59 by admin.

Pull Requests
URL Status Linked Edit
PR 26934 merged kj, 2021-06-28 14:33
PR 29033 merged Mark.Shannon, 2021-10-20 10:56
PR 29271 closed kj, 2021-10-28 14:37
PR 29595 merged Mark.Shannon, 2021-11-17 16:42
PR 29942 merged Mark.Shannon, 2021-12-06 14:38
PR 30011 merged Mark.Shannon, 2021-12-09 18:21
PR 30107 merged Mark.Shannon, 2021-12-14 19:11
PR 30415 closed Mark.Shannon, 2022-01-05 11:12
PR 31273 sobolevn, 2022-02-11 11:31
Messages (9)
msg396639 - (view) Author: Ken Jin (kj) * (Python committer) Date: 2021-06-28 14:22
CALL_FUNCTION can be specialized. Copying from Mark's comments https://github.com/faster-cpython/ideas/issues/54#issue-898013125

```
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 https://github.com/faster-cpython/ideas/issues/54#issuecomment-868978681 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.
msg404376 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2021-10-19 23:16
New changeset 3163e68c342434db37c69669017f96a4bb2d5f13 by Ken Jin in branch 'main':
bpo-44525: Specialize ``CALL_FUNCTION`` for C function calls (GH-26934)
https://github.com/python/cpython/commit/3163e68c342434db37c69669017f96a4bb2d5f13
msg404470 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2021-10-20 15:08
New changeset 8863a0fcc5f04ab7c3428e713917831f9b1deb18 by Mark Shannon in branch 'main':
bpo-44525: Specialize simple Python calls. (GH-29033)
https://github.com/python/cpython/commit/8863a0fcc5f04ab7c3428e713917831f9b1deb18
msg405108 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-10-27 16:19
Unfortunately, PR 26934 has broken thes 390x RHEL7 LTO 3.x buildbot as you can see before. As per the buildbot maintenance procedures, we will need to revert this PR unless is fixed in 24 hours.

@markshannon @Fidget-Spinner
msg405192 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2021-10-28 15:02
New changeset 0a1a36b74bdf8da286924a1c9652853b1c46f536 by Ken Jin in branch 'main':
bpo-44525: Add recursive checks for `CALL_FUNCTION_BUILTIN_O` (GH-29271)
https://github.com/python/cpython/commit/0a1a36b74bdf8da286924a1c9652853b1c46f536
msg406831 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2021-11-23 09:53
New changeset 135cabd328504e1648d17242b42b675cdbd0193b by Mark Shannon in branch 'main':
bpo-44525: Copy free variables in bytecode to allow calls to inner functions to be specialized (GH-29595)
https://github.com/python/cpython/commit/135cabd328504e1648d17242b42b675cdbd0193b
msg408554 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2021-12-14 18:22
New changeset 9f8f45144b6f0ad481e80570538cce89b414f7f9 by Mark Shannon in branch 'main':
bpo-44525: Split calls into PRECALL and CALL (GH-30011)
https://github.com/python/cpython/commit/9f8f45144b6f0ad481e80570538cce89b414f7f9
msg408609 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2021-12-15 15:03
New changeset 3a60bfef49b3324660a615a8e6d10710e5f669d9 by Mark Shannon in branch 'main':
bpo-44525: Specialize for calls to type and other builtin classes with 1 argument. (GH-29942)
https://github.com/python/cpython/commit/3a60bfef49b3324660a615a8e6d10710e5f669d9
msg409779 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2022-01-05 15:51
See https://github.com/faster-cpython/ideas/discussions/210
History
Date User Action Args
2022-04-11 14:59:47adminsetgithub: 88691
2022-02-11 11:31:07sobolevnsetnosy: + sobolevn
pull_requests: + pull_request29437
2022-01-05 15:51:32Mark.Shannonsetmessages: + msg409779
2022-01-05 11:12:24Mark.Shannonsetpull_requests: + pull_request28621
2021-12-15 15:03:46Mark.Shannonsetmessages: + msg408609
2021-12-14 19:11:03Mark.Shannonsetpull_requests: + pull_request28329
2021-12-14 18:22:52Mark.Shannonsetmessages: + msg408554
2021-12-09 18:21:23Mark.Shannonsetpull_requests: + pull_request28233
2021-12-06 14:38:05Mark.Shannonsetpull_requests: + pull_request28167
2021-11-23 09:53:40Mark.Shannonsetmessages: + msg406831
2021-11-17 16:42:22Mark.Shannonsetpull_requests: + pull_request27838
2021-10-29 16:13:01thesamesamsetnosy: + thesamesam
2021-10-28 15:02:56Mark.Shannonsetmessages: + msg405192
2021-10-28 14:37:50kjsetpull_requests: + pull_request27535
2021-10-27 16:19:18pablogsalsetnosy: + pablogsal
messages: + msg405108
2021-10-20 15:08:43Mark.Shannonsetmessages: + msg404470
2021-10-20 10:56:27Mark.Shannonsetpull_requests: + pull_request27355
2021-10-19 23:16:44Mark.Shannonsetmessages: + msg404376
2021-06-28 14:33:06kjsetkeywords: + patch
stage: patch review
pull_requests: + pull_request25503
2021-06-28 14:22:18kjcreate