Skip to content

Allow LOAD_FAST_BORROW with exception blocks #162066

Open

Description

@eendebakpt

Feature or enhancement

The compiler replaces LOAD_FAST by the cheaper LOAD_FAST_BORROW wherever it can show that the local variable outlives the loaded value. The pass that does this never looks at exception handlers, so code in a handler, or code that can only be reached through one, keeps its LOAD_FAST instructions. This affects except and finally bodies, the cleanup code of with statements, code after a try whose body returns, and all code that follows an async for loop.

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. added
    type-featureA feature request or enhancement
    performancePerformance or resource usage
    interpreter-core(Objects, Python, Grammar, and Parser dirs)
    on Nov 15, 2026
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