Skip to content

Disable tracking of frozenset objects with immutables in the GC #140232

Description

@eendebakpt

Feature or enhancement

Proposal:

Frozenset objects with immutable objects do not need to be tracked by the GC. A similar optimization is already in place for tuples (#48938, #140204).
In particular for longer running programs with immutable frozensets this is benefical.

Linked PRs

Activity

  1. added
    type-featureA feature request or enhancement
    performancePerformance or resource usage
    interpreter-core(Objects, Python, Grammar, and Parser dirs)
    on Oct 16, 2025
  2. markshannon commented on Oct 17, 2025

    @markshannon
    Member

    Why untrack eagerly, rather than lazily as we do for tuples?

    Also, frozensets are not used that much, but are generated by the bytecode compiler. All compiler generated frozensets do not need tracking, so explicitly untracking them during unmarshalling might be more valuable.

  3. eendebakpt commented on Oct 17, 2025

    @eendebakpt
    ContributorAuthor

    I used eager untracking to prevent having to do the check in the GC for each iteration, For the tuples there is a reason it has to be done in the GC (because tuples can be generated with NULL values and filled later).

    Frozensets are not used a lot indeed, but I do expect usage of immutable datasets (including the frozenset) to increase with the free-threading build being used more.

    Doing the untracking during unmarshalling is not something I considered. I think the bytecode compiler generated frozensets are already handled with the approach in the PR. Correct? If adding this to the unmarshalling, do you have a pointer where this should be roughly added in the codebase?

  4. added a commit that references this issue on Jan 28, 2026
  5. 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 usagetype-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions