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 — Top-of-stack caching in the interpreter · Issue #131498 · python/cpython

Top-of-stack caching in the interpreter #131498

New issue
Copy link
New issue
Copy link
Closed
Closed
Top-of-stack caching in the interpreter#131498
Copy link
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagePerformance or resource usagetype-featureA feature request or enhancementA feature request or enhancement

Description

@markshannon
markshannon
opened on Mar 20, 2025
Issue body actions

Top-of-stack caching is technique where one or more values on the top of the stack are kept in local variables, with the assumption that the C compiler will put them in registers.

We should implement this for the interpreter (tier 1).
We cannot afford to increase the number of instructions by much, so we'll have to use a fixed size cache of 1.
This will likely only produce a modest speedup, as the total memory traffic is unlikely to decrease. There should be some ILP improvements.

The main benefit of TOS caching is likely to be in the JIT where we can use a variable sized cache.
We want to do it in the interpreter first though, as it will be simpler and requires a subset of the changes needed for the JIT.

Linked PRs

  • GH-131498: Remove conditional stack effects #131499
  • GH-131498: Another refactoring of the code generator #131827
  • GH-131498: Cases generator: Parse down to C statement level. #131948
  • GH-131498: manage stacks automatically #132074
  • GH-131498: Allow 'peek' variables to be modified #132506
  • GH-131498: Replace single-element arrays with scalars in bytecodes.c #132615
  • gh-131498: Remove commented-out dead code in cases_generator/analyzer.py #141168
  • [3.15] gh-131498: Remove commented-out dead code in cases_generator/analyzer.py (GH-141168) #160461

Activity

  1. markshannon
    added a commit that references this issue on Mar 20, 2025

    GH-131498: Remove conditional stack effects (GH-131499)

    7ebd71e
  2. picnixz
    added
    type-featureA feature request or enhancementA feature request or enhancement
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    performancePerformance or resource usagePerformance or resource usage
    on Mar 22, 2025
  3. markshannon
    added a commit that references this issue on Mar 31, 2025

    GH-131498: Another refactoring of the code generator (GH-131827)

    c535a13
  4. python
    deleted a comment from hasanisaeed on Mar 31, 2025
  5. markshannon
    added 2 commits that reference this issue on Apr 2, 2025

    GH-131498: Cases generator: Parse down to C statement level. (GH-131948)

    ad053d8

    GH-131498: Cases generator: manage stacks automatically (GH-132074)

    7099c75
  6. picnixz
    added a commit that references this issue on Apr 5, 2025

    pythonGH-131498: Cases generator: manage stacks automatically (python…

    0b437c4
  7. markshannon
    added a commit that references this issue on Apr 14, 2025

    GH-131498: Cases generator: Allow input and 'peek' variables to be mo…

    844596c
  8. brandtbucher
    added a commit that references this issue on Apr 18, 2025

    GH-131498: Replace single-element arrays with scalars in bytecodes.c (G…

    40ae889
  9. markshannon commented on Jun 11, 2025

    @markshannon
    markshannon
    on Jun 11, 2025
    MemberAuthor
    More actions

    It turns out that caching a single value in the interpreter has no positive effect on performance. Probably what is happening is that any speedup from improved IPC is being undone by increased overhead of spilling around escapes.

    However, all the work done is necessary for #135379 which will improve performance.

  10. markshannon
    closed this as completedon Jun 11, 2025
  11. ambv
    added 2 commits that reference this issue on Oct 23, 2026

    gh-131498: Remove commented-out dead code in cases_generator/analyzer…

    1c75034

    [3.15] gh-131498: Remove commented-out dead code in cases_generator/a…

    c4f6007
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

    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagePerformance or resource usagetype-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.