Skip to content

Optimise keyword arguments in the JIT #150724

Open

Description

@markshannon

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

Activity

  1. added
    performancePerformance or resource usage
    interpreter-core(Objects, Python, Grammar, and Parser dirs)
    3.16new features, bugs and security fixes
    on Jun 1, 2026
  2. brijkapadia commented on Jun 5, 2026

    @brijkapadia
    Contributor

    @markshannon Where would you put the optimization to switch bytecode instructions for the jit? After completing a trace, the jit will only see the uops, which would make it harder to do the proposed change for CALL_KW_PY.

  3. added a commit that references this issue on Jun 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.16new features, bugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagetopic-JIT

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions