Skip to content

Optimize calling pure python descriptor __get__ with vectorcall  #95977

Description

@kumaraditya303

Benchmark:

import pyperf
from pyperf import Runner


class Descr:

    def __init__(self, value):
        self.value = value

    def __get__(self, instance, owner):
        return self.value


class A:
    x = Descr(1)


def bench(loops):
    a = A()
    t1 = pyperf.perf_counter()
    for _ in range(loops):
        a.x
    t2 = pyperf.perf_counter()
    return t2 - t1


runner = Runner()
runner.bench_time_func('descriptor', bench)

Results:

@kumaraditya303 ➜ /workspaces/cpython (main ✗) $ ./python -m pyperf compare_to base.json patch.json 
Mean +- std dev: [base] 102 ns +- 6 ns -> [patch] 88.5 ns +- 4.0 ns: 1.15x faster

Activity

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

Metadata

Metadata

Labels

3.12only security fixesperformancePerformance or resource usage

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions