Skip to content

gh-145685: Avoid contention on TYPE_LOCK in super() lookups#145775

Open
colesbury wants to merge 3 commits intopython:mainfrom
colesbury:gh-145685-super-lookup-mro
Open

gh-145685: Avoid contention on TYPE_LOCK in super() lookups#145775
colesbury wants to merge 3 commits intopython:mainfrom
colesbury:gh-145685-super-lookup-mro

Conversation

@colesbury
Copy link
Contributor

@colesbury colesbury commented Mar 10, 2026

Copy link
Contributor

@mpage mpage left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Should we add a test to the scaling benchmark that reproduces the issue?

Comment on lines +12371 to +12372
_PyThreadState_PushCStackRef(tstate, &mro_ref);
mro_ref.ref = PyStackRef_FromPyObjectNew(mro);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't need to be in this PR, but would it be worth adding another function that combines these two operations?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, makes sense.

@colesbury
Copy link
Contributor Author

This is enough to fix super() on different classes, but not enough for the straightforward super() on the same class. That'll require some additional fixes. I'll add the scaling benchmark in a follow up together with those fixes:

class Base:
    def method(self):
        return 1

class Derived(Base):
    def method(self):
        return super().method()

@register_benchmark
def super_call():
    obj = Derived()
    for _ in range(1000 * WORK_SCALE):
        obj.method()

@colesbury
Copy link
Contributor Author

Actually, maybe it's worth adding the different class benchmark now and I'll update it later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants