Skip to content

Optimize reference counting overhead of LOAD_FAST variants #130704

Closed

Description

@mpage

Feature or enhancement

Proposal:

LOAD_FAST and its super instruction form are the most frequently executed bytecode instructions in most Python programs (they represent ~20% of dynamic instruction frequency on the benchmark suite). While they are very cheap (they're just an incref and a push to the stack), they are not free. If we can prove that the reference in the frame outlives the reference that is loaded on the stack we can use a cheaper variant of LOAD_FAST that loads an appropriately tagged borrowed reference onto the operand stack, thereby avoiding the incref/decref.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

faster-cpython/ideas#700

Linked PRs

Activity

  1. added
    type-featureA feature request or enhancement
    interpreter-core(Objects, Python, Grammar, and Parser dirs)
    on Feb 28, 2025
  2. added a commit that references this issue on Apr 1, 2025
  3. added 2 commits that reference this issue on Apr 29, 2025
  4. added a commit that references this issue on Jul 12, 2025
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