Skip to content

JIT optimizer cleanups #143421

Description

@Fidget-Spinner

Feature or enhancement

Proposal:

Currently the JIT uop buffer modifies uops traces in place.

I think we should make it add to a new buffer. Having modifications be in-place is making our code messy and full of special cases.

So

REPLACE_OP(this_instr, ...)

should become

ADD_OP(ctx, ...)

in optimizer_bytecodes.c,

Also, the default generated case of optimizer_bytecodes.c should be to ADD_OP(pc, ...)

This is also blocking optimization in #143414, as ocassionally we need to insert extra guards to check the uniqueness of an object for example.

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

Linked PRs

Activity

  1. markshannon commented on Jan 5, 2026

    @markshannon
    Member

    I agree, but let's refactor the JIT structs to be heap allocated first.

  2. Fidget-Spinner commented on Jan 6, 2026

    @Fidget-Spinner
    MemberAuthor

    I agree, but let's refactor the JIT structs to be heap allocated first.

    Assigning this to @cocolato

  3. changed the title [-]Make the JIT optimizer buffer add to a new buffer, not in-place[/-] [+] JIT optimizer cleanups[/+] on Jan 6, 2026
  4. added 4 commits that reference this issue on Jan 8, 2026
  5. cocolato commented on Jan 10, 2026

    @cocolato
    Member

    How should we handle the following case? It appears that we cannot simply use ADD_OP as a substitute. Perhaps we still need a REPLACE_OP to handle the new buffer.

    REPLACE_OP(this_instr-1, _GUARD_GLOBALS_VERSION, 0, version);
    and
    REPLACE_OP(this_instr+1, _NOP, 0, 0);

  6. Fidget-Spinner commented on Jan 10, 2026

    @Fidget-Spinner
    MemberAuthor

    @cocolato make REPLACE_OP operate on the new buffer instead of the old one. Ideally you should have two buffers. An old buffer containing the current uops, and a new buffer, containing the uops being written.

    If the optimizer stops early, you can just insert an _EXIT_TRACE at that location in the new buffer.

  7. added 3 commits that reference this issue on Jan 12, 2026
  8. added a commit that references this issue on Jan 17, 2026
  9. added 4 commits that reference this issue on Feb 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

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

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions