GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Optimize the JIT's low-level assembly control flow · Issue #135904 · python/cpython

Optimize the JIT's low-level assembly control flow #135904

New issue
Copy link
New issue
Copy link
Closed
Closed
Optimize the JIT's low-level assembly control flow#135904
Copy link
Assignees
diegorussobrandtbucher
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagePerformance or resource usagetopic-JITtype-featureA feature request or enhancementA feature request or enhancement

Description

@brandtbucher
brandtbucher
opened on Jun 24, 2025
Issue body actions

Currently, our JIT backend mostly just takes the machine code that Clang gives us, and emits it without modification. The one exception to this is removing zero-length jumps to the next uop at the end of each blob of machine code, which is both fragile and extremely limited in what it can do.

For example, consider _GUARD_NOS_NULL. This is the (16-byte) sequence that Clang gives us:

cmpq    $0x1, -0x10(%r13)
je      _JIT_CONTINUE
jmp     _JIT_JUMP_TARGET

And this is the (11-byte) sequence we want:

cmpq    $0x1, -0x10(%r13)
jne      _JIT_JUMP_TARGET

We should do a bit more here, and doing more is a lot easier if we're modifying textual assembly at build time. Thankfully, this is pretty straightforward: we just compile to assembly using Clang (-S), modify it, and finish compiling using Clang again.

We should intentionally not take on too much complexity here, especially since we support a few different platforms. There's a lot that we can do by only reasoning about labels, jumps, branches, and returns and treating all other sequences of instructions as black boxes. Once we have the assembly parsed into basic blocks, we can do things like:

  • Inverting the direction of branches (from branch-hot/jump-cold to branch-cold/jump-hot) like in _GUARD_NOS_NULL above is straightforward.
  • Having the assembler encode all _JIT_CONTINUE jumps during this step (by just adding the label at the end of the assembly) instead of doing it at runtime. It will also use more efficient "short" jump encodings most of the time, as an additional benefit.
  • Removing zero length jumps, as we do now, is trivial.
  • Later: Splitting the stencils into "hot" (core uop logic) and "cold" (deopts, error handling, etc) code. The JIT will emit all "hot" code for a trace, followed by all cold code for a trace, keeping the cold code out-of-line.

I have a branch to do all but the last of these, and will open a PR soon.

Linked PRs

  • GH-135904: Optimize the JIT's assembly control flow #135905
  • GH-135904: Improve the JIT's performance on macOS #136528
  • GH-135904: Add tests for the JIT build process #136766
  • GH-135904: Implement assembler optimization for AArch64. #139855
  • GH-135904: JIT compiler: Support 19 bit branch instructions on AArch64 for Mach-O. #140453
Reacted by Sergey Miryanov, Diego Russo, Ken Jin and Mikhail Efimov

Activity

  1. brandtbucher
    self-assigned this
    on Jun 24, 2025
  2. brandtbucher
    added
    performancePerformance or resource usagePerformance or resource usage
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    topic-JIT
    3.15bugs and security fixesbugs and security fixes
    on Jun 24, 2025
  3. brandtbucher
    changed the title [-]JIT Assembly Optimization[/-] [+]JIT assembly optimization[/+] on Jun 24, 2025
  4. brandtbucher
    changed the title [-]JIT assembly optimization[/-] [+]Optimize the JIT's low-level assembly control flow[/+] on Jun 24, 2025
  5. picnixz
    added
    type-featureA feature request or enhancementA feature request or enhancement
    and removed
    3.15bugs and security fixesbugs and security fixes
    on Jun 27, 2025
  6. brandtbucher
    added a commit that references this issue on Jun 27, 2025

    GH-135904: Optimize the JIT's assembly control flow (GH-135905)

    0e5d096
  7. brandtbucher
    assigned
    diegorusso
    on Jun 27, 2025
  8. AndPuQing
    added a commit that references this issue on Jul 11, 2025

    pythonGH-135904: Optimize the JIT's assembly control flow (pythonGH-1…

    d048a8c
  9. Pranjal095
    added a commit that references this issue on Jul 12, 2025

    pythonGH-135904: Optimize the JIT's assembly control flow (pythonGH-1…

    29cab8c
  10. brandtbucher
    added a commit that references this issue on Jul 14, 2025

    GH-135904: Improve the JIT's performance on macOS (GH-136528)

    3d8c38f
  11. taegyunkim
    added 2 commits that reference this issue on Aug 4, 2025

    pythonGH-135904: Optimize the JIT's assembly control flow (pythonGH-1…

    8d9a6b7

    pythonGH-135904: Improve the JIT's performance on macOS (pythonGH-136528

    d645168
  12. Agent-Hellboy
    added 2 commits that reference this issue on Aug 19, 2025

    pythonGH-135904: Optimize the JIT's assembly control flow (pythonGH-1…

    a6c7345

    pythonGH-135904: Improve the JIT's performance on macOS (pythonGH-136528

    bfbbdc9
  13. markshannon
    added 2 commits that reference this issue on Oct 17, 2025

    GH-135904: Implement assembler optimization for AArch64. (GH-139855)

    f188385

    GH-135904: JIT compiler: Support 19 bit branch instructions on AArch6…

    61e759c
  14. StanFromIreland
    added 2 commits that reference this issue on Dec 6, 2025

    pythonGH-135904: Implement assembler optimization for AArch64. (pytho…

    0156947

    pythonGH-135904: JIT compiler: Support 19 bit branch instructions on …

    fc9819e
  15. markshannon commented on Dec 19, 2025

    @markshannon
    markshannon
    on Dec 19, 2025
    Member
    More actions

    @brandtbucher can we close this? I think it is done.

  16. Fidget-Spinner commented on Dec 25, 2025

    @Fidget-Spinner
    Fidget-Spinner
    on Dec 25, 2025
    Member
    More actions

    There's still hot-cold splitting. We can have another issue for that.

  17. Fidget-Spinner
    closed this as completedon Dec 25, 2025
  18. Fidget-Spinner commented on Dec 25, 2025

    @Fidget-Spinner
    Fidget-Spinner
    on Dec 25, 2025
    Member
    More actions

    Follow-up on hot-cold splitting here #143158

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

Metadata

Metadata

Assignees

  • @brandtbucher
    brandtbucher
  • @diegorusso
    diegorusso

Labels

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

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.