Skip to content

LOAD_FAST_BORROW; POP_TOP pairs should be removed #152600

Open

Description

@brijkapadia

Feature or enhancement

Proposal:

I noticed that

def f(x):
    x

produces these instructions:

  3           RESUME                   0

  4           LOAD_FAST_BORROW         0 (x)
              POP_TOP
              LOAD_COMMON_CONSTANT     7 (None)
              RETURN_VALUE
Full reproducer

from dis import dis

def f(x):
    x

dis(f)

The compiler should get rid of any LOAD_FAST_BORROW; POP_TOP pairs.

I will work on this.

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:

No response

Linked PRs

Activity

  1. picnixz commented on Jun 29, 2026

    @picnixz
    Member
  2. markshannon commented on Jun 29, 2026

    @markshannon
    Member

    Not a common pattern, but we might as well fix it.
    LOAD_FAST and LOAD_CONSTANT as well.

  3. brijkapadia commented on Jun 29, 2026

    @brijkapadia
    ContributorAuthor

    I think that constants are already removed.
    Also I think this will help #145749.

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 usagetopic-parsertype-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions