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 — Hot-cold splitting in the cases generator and JIT optimizer. · Issue #150712 · python/cpython

Hot-cold splitting in the cases generator and JIT optimizer. #150712

New issue
Copy link
New issue
Copy link
Open
Open
Hot-cold splitting in the cases generator and JIT optimizer.#150712
Copy link
Labels
3.16new features, bugs and security fixesnew features, bugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagePerformance or resource usagetopic-JIT

Description

@markshannon
markshannon
opened on Jun 1, 2026
Issue body actions

#143158 describes hot-cold splitting in the JIT, but that is too late for optimizations that sink code onto exits.

To support those optimizations, we need to split uops as defined into bytecodes.c into "hot" and "cold" ops.

From #143158 (comment)

For example, we want to transform this:

        op (_GUARD_IS_NONE_POP, (val -- )) {
            int is_none = PyStackRef_IsNone(val);
            if (!is_none) {
                PyStackRef_CLOSE(val);
                AT_END_EXIT_IF(1);
            }
            DEAD(val);
        }

into this:

        op (_GUARD_IS_NONE_POP, (val -- )) {
            int is_none = PyStackRef_IsNone(val);
            if (!is_none) {
                goto _GUARD_IS_NONE_POP_COLD; // tail call
            }
            DEAD(val);
        }

        op (_GUARD_IS_NONE_POP_COLD, (val -- )) {
            PyStackRef_CLOSE(val);
            AT_END_EXIT_IF(1);
        }

Currently, during lowering of the uop trace to a form suitable for execution we need to insert an _EXIT_TRACE uop as the target for exit jumps in the uop. We want to replace those with the "cold" uop followed by the exit, allowing compensation code to be more easily sunk onto side exits.

While it is appealing to do this automatically, it might make more sense to do the splitting manually, and add support for custom exits to the tooling.

We could mark ops as exit and explicitly state which exit is being used (with _EXIT_TRACE as the default exit).
So _GUARD_IS_NONE_POP would be rewritten as:

        op (_GUARD_IS_NONE_POP, (val -- )) {
            int is_none = PyStackRef_IsNone(val);
            if (!is_none) {
                EXIT_TO(POP_TOP_EXIT);
            }
            DEAD(val);
        }

        exit op (POP_TOP_EXIT, (val -- )) {
            PyStackRef_CLOSE(val);
        }

Likewise, _ITER_NEXT_INLINE would be rewritten as:

    tier2 op(_ITER_NEXT_INLINE, (iternext_fn/4, iter, null_or_index -- iter, null_or_index, next)) {
        assert(sizeof(iternextfunc) == sizeof(uintptr_t));
        volatile iternextfunc iternext_v = (iternextfunc)iternext_fn;
        PyObject *item = iternext_v(PyStackRef_AsPyObjectBorrow(iter));
        if (item == NULL) {
            EXIT_TO(_ITER_NEXT_INLINE_EXIT);
        }
        STAT_INC(FOR_ITER, hit);
        next = PyStackRef_FromPyObjectSteal(item);
    }

    exit op(_ITER_NEXT_INLINE_EXIT, ( -- )) {
        if (_PyErr_Occurred(tstate)) {
            if (_PyErr_ExceptionMatches(tstate, PyExc_StopIteration)) {
                _PyEval_MonitorRaise(tstate, frame, frame->instr_ptr);
                _PyErr_Clear(tstate);
            }
            else {
                ERROR_NO_POP();
            }
        }
   }

Activity

  1. markshannon
    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.16new features, bugs and security fixesnew features, bugs and security fixes
    on Jun 1, 2026
  2. waterlens commented on Jun 2, 2026

    @waterlens
    waterlens
    on Jun 2, 2026
    More actions

    Thanks for writing this up. I'd like to take it on.

  3. waterlens commented on Jun 9, 2026

    @waterlens
    waterlens
    on Jun 9, 2026
    More actions

    I just saw the discussion on https://discuss.python.org/t/an-announcement-from-the-steering-council-regarding-the-jit-project/107638/31 😢
    Following up closely.

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 fixesnew features, bugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagePerformance or resource usagetopic-JIT

    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.