Skip to content

Free threaded scaling issues with @classmethod and @staticmethod #145779

Description

@colesbury

Bug report

We have reference count contention from:

  1. The classmethod object, which is stored in the MRO cache. This should be pretty easy to fix (enable deferred reference counting when creating the object).

  2. sm_descr_get increfs sm->sm_callable

  3. cm_descr_get creates a new PyMethod_New, which increfs cm->cm_callable and the containing class

ftscalingbench.py

class MyClassMethod:
    @classmethod
    def my_classmethod(cls):
        return cls

    @staticmethod
    def my_staticmethod():
        pass

@register_benchmark
def classmethod_call():
    obj = MyClassMethod()
    for _ in range(1000 * WORK_SCALE):
        obj.my_classmethod()

@register_benchmark
def staticmethod_call():
    obj = MyClassMethod()
    for _ in range(1000 * WORK_SCALE):
        obj.my_staticmethod()

Linked PRs

Activity

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

    3.14bugs and security fixes3.15pre-release feature fixes, 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