Skip to content

Top-of-stack caching in the interpreter #131498

Description

@markshannon

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

Activity

  1. added a commit that references this issue on Mar 20, 2025
  2. added
    type-featureA feature request or enhancement
    interpreter-core(Objects, Python, Grammar, and Parser dirs)
    performancePerformance or resource usage
    on Mar 22, 2025
  3. added a commit that references this issue on Mar 31, 2025
  4. deleted a comment from hasanisaeed on Mar 31, 2025
  5. added 2 commits that reference this issue on Apr 2, 2025
  6. added a commit that references this issue on Apr 5, 2025
  7. added a commit that references this issue on Apr 14, 2025
  8. added a commit that references this issue on Apr 18, 2025
  9. markshannon commented on Jun 11, 2025

    @markshannon
    MemberAuthor

    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.

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)performancePerformance or resource usagetype-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions