Skip to content

Workflow for 3.12 cycle

Eric Snow edited this page Oct 26, 2022 · 17 revisions

(Graphical version at the end)

Multi-core Python

A per-interpreter GIL

  • PEP 684: A Per-interpreter GIL

  • A CI check to prevent new globals in CPython code

    • Tooling to identify global variables in CPython code
  • Interpreter isolation (_PyRuntimeState -> PyInterpreterState)

    • Consolidate global state to _PyRuntimeState

      • Tooling to identify global variables in CPython code (also above)
    • PEP 683 - immortal objects

    • mimalloc (not required)

  • Restrictions on interpreter capability (e.g. no threading)

    • Per-interpreter config & func to specify restrictions
  • Per-interpreter isolation for extension modules

    • An import check for extension subinterpreter compatibility

Expose multiple interpreters to Python code

  • Implement PEP 554

    • PEP 554 - Multiple Interpreters in the Stdlib

Reduced Reference Count Overhead

Reduced reference counting overhead

  • Optimize flow of references in C, transferring ownership when needed

    • Identify flow of references in C
  • Static reduction in refcount operations

    • Bytecode compiler enhancements Irit

    • Deferred reference counts

  • Deferred reference counts (also above)

Improve cycle GC

  • (Task needs breaking up)

Compact Objects

Compact objects

  • Merge managed dict and values pointer into one word

  • One word GC header

    • Saturating refcounts

Specialization

Finish specialization

  • Specialize SEND

    • Specialize FOR_ITER for generator

      • Specialize FOR_ITER for sequences Dennis

      • Shim frames on entry to PyEval_EvalDefault

        • Identify main sources of calls to PyEval_EvalFrame
    • Move PEP 380 logic into compiler Brandt

Trace optimized interpreter

Projected (short) trace opimized interpreter

  • Optimize traces: Guard stengthening and elimination

    • Trace interpreter (also below)
  • Optimize traces: Allocation elimination

    • Trace interpreter

      • Breakup instruction definitions into 'mini-ops' (see below)

      • Trace projection: Create traces from hotspots

        • Detect hotspots in code

          • Only unconditional jumps should go backwards
        • Implement optimizer API

        • Generate version of the interpreter better suited to emscripten and web assembly

        • Breakup instruction definitions into 'mini-ops'

          • Move opcode definitions to their own file and generate PyEval_EvalDefault (also below)

            • Move PEP 380 logic into compiler Brandt (also above)
          • Encapasulate GIL code and move it out of ceval.c #93177

  • Generate version of the interpreter better suited to emscripten and web assembly (goal without dependents?)

    • Move opcode definitions to their own file and generate PyEval_EvalDefault (also above)
graph LR

%% High level goals

    CompactObject[["Compact objects"]]
    
    ReducedRefcount[["Reduced reference counting overhead"]]
    
    SpecDone[["Finish specialization"]]
    
    Traces[["Projected (short) trace opimitized interpreter"]]

    InterpretersInPythonCode[["Expose multiple interpreters to Python code"]]

    PerInterpreterGIL[["A per-interpreter GIL"]]

%% Tasks

    Compiler("Bytecode compiler enhancements<br/><b>Irit</b>")
    
    StaticRefcntReduction("Use static analysis to reduce<br/>reference count operations")

    SpecSeq("Specialize FOR_ITER for sequences<br/><b>Dennis</b>")

    SpecGen("Specialize FOR_ITER for generator")
    
    SpecClass("Specialize CALL for Python classes")
    
    CtoPy("Identify main sources of<br/>calls to PyEval_EvalFrame")

    ShimFrame("Shim frames on entry<br/>to PyEval_EvalDefault")

    SpecSend("Specialize SEND")
    
    SatRefcnt("Saturating refcounts")

    380("Move PEP 380 logic into compiler<br/><b>Brandt</b> ")

    EncapsulateGIL("Encapasulate GIL code and<br/>move it out of ceval.c #93177")

    OpcodesOwnFile("Move opcode definitions to their own file<br/>and generate PyEval_EvalDefault")

    CycleGC("Improve cycle GC<br/>(Task needs breaking up)")

    MiniOps("Breakup instruction definitions into 'mini-ops'")
    
    SmallGCHead("One word GC header")
    
    MergeDictValuePointers("Merge managed dict and values<br/>pointer into one word")
 
    TrackRefsInC("Identify flow of references in C")
    
    OptRefsInC("Optimize flow of references in C,<br/>transferring ownership when needed")
    
    GuardOpt("Optimize traces:<br/>Guard stengthening and elimination")

    SafeDecref("Defer side effecting code in Py_DECREF()")
    
    AllocSinking("Optimize traces:<br/>Allocation elimination")
    
    AllBranchesForward("Only unconditional jumps should go backwards")
    
    HotSpotDetection("Detect hotspots in code")
    
    TraceProjection("Trace projection:<br/>Create traces from hotspots")
    
    TraceEval("Trace interpreter")
    
    OptAPI("Implement optimizer API")
    
    Deferred("Deferred reference counts")
    
    StaticRefcntReduction("Static reduction in refcount operations")
    
    WebAssemblyFriendlyInterpreter("Generate version of the interpreter better<br/>suited to emscripten and web assembly")

    PEP554("PEP 554 - Multiple Interpreters in the Stdlib")

    PEP554Impl("Implement PEP 554")

    ExtensionIsolation("Per-interpreter isolation for extension modules")

    ExtensionCompatCheck("An import check for extension subinterpreter compatibility")

    CAnalyzer("Tooling to identify global variables in CPython code")

    GlobalsCICheck("A CI check to prevent new globals in CPython code")

    ConsolidateGlobals("Consolidate global state to _PyRuntimeState")

    ImmortalObjects("PEP 683 - immortal objects")

    InterpreterIsolation("Interpreter isolation (_PyRuntimeState -> PyInterpreterState)")

    InterpretersAPI("Per-interpreter config & func to specify restrictions")

    InterpreterRestrictions("Restrictions on interpreter capability (e.g. no threading)")

    PEP684("PEP 684 - A Per-Interpreter GIL")

%% Dependencies

    380 --> OpcodesOwnFile
    380 --> SpecSend

    subgraph Trace optimized interpreter
    AllBranchesForward --> HotSpotDetection
    HotSpotDetection --> TraceProjection
    OpcodesOwnFile --> MiniOps
    EncapsulateGIL --> OpcodesOwnFile
    OpcodesOwnFile --> WebAssemblyFriendlyInterpreter
    OptAPI --> TraceProjection
    MiniOps --> TraceProjection
    TraceProjection --> TraceEval
    MiniOps --> TraceEval
    SafeDecref --> GuardOpt
    SafeDecref --> AllocSinking
    TraceEval --> GuardOpt
    TraceEval --> AllocSinking
    GuardOpt --> Traces
    AllocSinking --> Traces
    end

    subgraph Specialization
    CtoPy --> ShimFrame
    SpecSeq --> SpecGen
    ShimFrame --> SpecGen
    SpecGen --> SpecSend
    SpecSend --> SpecDone
    SpecClass --> SpecDone
    end

    subgraph Compact Objects
    SatRefcnt --> SmallGCHead
    MergeDictValuePointers --> CompactObject
    SmallGCHead --> CompactObject
    end

    subgraph Reduced Reference Count Overhead
    TrackRefsInC --> OptRefsInC
    OptRefsInC --> ReducedRefcount
    Compiler --> StaticRefcntReduction
    Deferred --> StaticRefcntReduction
    Deferred --> ReducedRefcount
    StaticRefcntReduction --> ReducedRefcount
    end

    subgraph Multi-core Python
    ExtensionIsolation --> ExtensionCompatCheck
    ExtensionCompatCheck --> PerInterpreterGIL
    CAnalyzer --> ConsolidateGlobals
    CAnalyzer --> GlobalsCICheck
    GlobalsCICheck --> PerInterpreterGIL
    ConsolidateGlobals --> InterpreterIsolation
    ImmortalObjects --> InterpreterIsolation
    InterpreterIsolation --> PerInterpreterGIL
    InterpretersAPI --> InterpreterRestrictions
    InterpreterRestrictions --> PerInterpreterGIL
    PEP684 --> PerInterpreterGIL

    PEP554 --> PEP554Impl
    PEP554Impl --> InterpretersInPythonCode
    end

%% Links and colors
    click TrackRefsInC "https://github.com/faster-cpython/ideas/issues/441"
    click OptRefsInC "https://github.com/faster-cpython/ideas/issues/442"
    click Deferred "https://github.com/faster-cpython/ideas/issues/443"
    click StaticRefcntReduction "https://github.com/faster-cpython/ideas/issues/444"

    click ShimFrame "https://github.com/faster-cpython/ideas/issues/436"
    click SpecSeq "https://github.com/faster-cpython/ideas/issues/67"
    click SpecClass "https://github.com/python/cpython/pull/31707"

    click 380 "https://github.com/python/cpython/pull/31968"

    click MergeDictValuePointers "https://github.com/python/cpython/pull/95278"
    style MergeDictValuePointers fill:#88f

    click PEP554 "https://peps.python.org/pep-0554/"
    click ImmortalObjects "https://peps.python.org/pep-0683/"
    click PEP684 "https://peps.python.org/pep-0684/"
    style CAnalyzer fill:#88f
    click ExtensionIsolation "https://peps.python.org/pep-0630/"
    style ExtensionIsolation fill:#88f
    style InterpretersAPI fill:#88f
    style InterpreterRestrictions fill:#88f
Loading