Skip to content

Unexpected scaling bottleneck in _PyType_Lookup / _PyType_LookupStackRefAndVersion #145685

@colesbury

Description

@colesbury

Bug report

There are scaling bottlenecks in the slow paths of _PyType_LookupStackRefAndVersion(), and it turns out that these can be a major bottleneck in larger applications.

For context, I've been testing Zulip with 3.14t and multithreading. The problem is basically:

  1. There are a lot of attribute loads that are not monomorphic (so specialization is of limited help)
  2. There are lots of unique (type, attr) lookups, so there are frequent collisions in the global MRO cache

The slow path for this case acquires the global type lock.

We should avoid acquiring the global type lock if the type already has a valid version tag. We'll also want to avoid reference count contention on the MRO tuple.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.14bugs and security fixes3.15new features, bugs and security fixesperformancePerformance or resource usagetopic-free-threadingtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions