python / python/cpython

Some (mostly) easy ways to reduce the size of JIT generated code

Open
#145,742 2 comments 1 reaction 1 assignee View on GitHub

@corona10 is already working on this.

Since Mar 24, 2026.

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

Description

Reducing the size of JIT generated code makes it faster, often super-linearly as there is less code to execute and less code to fill caches.

Looking at the top instructions from old but mostly still valid stats there are a few opportunities to reduce code size:

_SET_IP

Most uses of _SET_IP are setting the ip just in case something wants to inspect it. For these cases, we could store a 16 bit offset instead of the full 64 bit pointer. Code that reads the instruction pointer would need updating, but this should reduce the overhead of _SET_IP by more than half.

_LOAD_CONST_INLINE_BORROW and similar

We can do the tagging when generating the code, instead of while executing. This only saves a single instruction, but it helps.

_LOAD_FAST_BORROW

We already replicate _LOAD_FAST_BORROW, but that still leaves most _LOAD_FAST_BORROW using the slower version, and bloating the stencils.
We could manually generate the code, it is only a couple of instructions, reducing stencil bloat and covering all operands

Linked PRs
  • gh-148081
  • gh-148217
  • gh-148436

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.