Skip to content

Eliminate redundant refcounting in the JIT for LOAD_ATTR_MODULE #143995

Closed

Description

@aisk

Feature or enhancement

Proposal:

As a follow-up to #134584, we can eliminate redundant ref-counting for LOAD_ATTR_MODULE.

Note that if a module is imported globally (as is most commonly done, at the top of a file), attribute access via LOAD_ATTR_MODULE may be optimized into a constant load. Therefore, this optimization only applies when a module is imported locally, for example, within a function.

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 Jan 18, 2026
  2. Fidget-Spinner commented on Jan 18, 2026

    @Fidget-Spinner
    Member

    I don't think we should optimize for this. This case is very rare and we introduce more complexity to the interpreter.

    If you want, perhaps optimize _BINARY_OP or _BINARY_OP_EXTEND instead?

  3. aisk commented on Jan 18, 2026

    @aisk
    MemberAuthor

    Hi @Fidget-Spinner, thanks for the reply. I’ll give these a try.

  4. added
    pendingThe issue will be closed if no feedback is provided
    on Jan 18, 2026
  5. removed
    pendingThe issue will be closed if no feedback is provided
    on Jan 24, 2026
  6. Fidget-Spinner commented on Jan 24, 2026

    @Fidget-Spinner
    Member

    I've changed my mind. I think this is worthwhile when we fail to promote globals. Let's do this!

  7. added a commit that references this issue on Jan 25, 2026
  8. added a commit that references this issue on Feb 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 usagetopic-JITtype-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions