Skip to content

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

Open

Description

@markshannon

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

Activity

  1. corona10 commented on Mar 24, 2026

    @corona10
    Member

    I’ll take a look at this issue and sync with @Fidget-Spinner on the approach.

  2. self-assigned this
    on Mar 24, 2026
  3. Fidget-Spinner commented on Mar 24, 2026

    @Fidget-Spinner
    Member

    Specifically @corona10 is taking up _LOAD_CONST_INLINE_BORROW folding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

interpreter-core(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagetopic-JITtype-featureA feature request or enhancement

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions