python / python/cpython

Optimise keyword arguments in the JIT

Open
#150,724 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

3.16 interpreter-core performance topic-JIT
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Since the JIT traces can see both sides of the call, it can remove the work done to parse and shuffle the arguments during optimization.

For example, calling the function

def foo(a, b): pass

with keyword arguments:

foo(0, b=2, a=1)

requires the tuple ("b", "a") to pushed to the stack after the arguments
and for the CALL_KW_PY instruction to parse and reorder the arguments.

We can work out the reordering required and emit the necessary stack permuting code,
then replace the CALL_KW_PY with a much more effcient CALL_PY_EXACT_ARGS

In the example above:

LOAD_CONSTANT ("b", "a")
CALL_KW_PY 3

can be replaced with

SWAP 2
CALL_PY_EXACT_ARGS 3
Linked PRs
  • gh-151389

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the JIT handling of CALL_KW_PY and CALL_PY_EXACT_ARGS, using the keyword-call example in the issue to understand the required argument reordering. Done means the JIT can replace the keyword call with stack-permuting code and an exact-argument call while preserving the shown call behavior; gh-151389 is linked to this work.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers, performance
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.