Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize calling pure python descriptor __get__ with vectorcall #95977

Closed
kumaraditya303 opened this issue Aug 14, 2022 · 0 comments · Fixed by #95978
Closed

Optimize calling pure python descriptor __get__ with vectorcall #95977

kumaraditya303 opened this issue Aug 14, 2022 · 0 comments · Fixed by #95978
Assignees
Labels
3.12 performance

Comments

@kumaraditya303
Copy link
Contributor

kumaraditya303 commented Aug 14, 2022

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.12 performance
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant