Visitar URL original
bpo-45295: Speed up C classmethod calls via unbound classmethods by Fidget-Spinner · Pull Request #28572 · python/cpython · GitHub
The Wayback Machine - https://web.archive.org/web/20220519222500/https://github.com/python/cpython/pull/28572
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

bpo-45295: Speed up C classmethod calls via unbound classmethods #28572

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

Fidget-Spinner
Copy link
Member

@Fidget-Spinner Fidget-Spinner commented Sep 26, 2021 •

  1. _PyObject_GetMethod now supports C classmethods.
  2. PyClassMethodDescr_Type now supports vectorcall.

This PR has two changes because supporting vectorcall made it easier to call unbound cclassmethods. Without vectorcall, I'd need to write a lot of custom code.

Moving to vectorcall also means we can get rid of the old calling code :).

Microbench on Windows Release, pyperformance coming later (once tests pass):

python.exe -m timeit "int.from_bytes(b'')"
Main:
2000000 loops, best of 5: 107 nsec per loop
Patched:
5000000 loops, best of 5: 72.4 nsec per loop

This is without specialization support. That will come in another PR.

https://bugs.python.org/issue45295

@Fidget-Spinner
Copy link
Member Author

@Fidget-Spinner Fidget-Spinner commented Sep 26, 2021

I've cancelled the workflows temporarily to save resources. test_descr and test_datetime currently fail.

@Fidget-Spinner Fidget-Spinner changed the title bpo-issue45295: Speed up C classmethod calls via unbound classmethods bpo-45295: Speed up C classmethod calls via unbound classmethods Sep 27, 2021
@Fidget-Spinner Fidget-Spinner marked this pull request as ready for review Sep 27, 2021
@Fidget-Spinner
Copy link
Member Author

@Fidget-Spinner Fidget-Spinner commented Sep 27, 2021

Pinging @markshannon as I think this may interest you. Not sure who else to ping for descriptor stuff, maybe the original LOAD_METHOD + CALL_METHOD folks?

@Fidget-Spinner
Copy link
Member Author

@Fidget-Spinner Fidget-Spinner commented Sep 29, 2021

Knowing my luck with benchmarks, pyperformance showed no change :(.

The current code allows for improving Python classmethods too. After implementing that I will try running this against the Pyston benchmark suite instead (pyperformance almost doesnt use any classmethods).

If that too doesnt show any speedups i will just abandon this PR.

@markshannon
Copy link
Member

@markshannon markshannon commented Oct 18, 2021

What are you trying to speed up here? Could you provide an example?

@Fidget-Spinner
Copy link
Member Author

@Fidget-Spinner Fidget-Spinner commented Oct 18, 2021 •

What are you trying to speed up here? Could you provide an example?

All builtin classmethod calls. So int.from_bytes(), dict.fromkeys() etc. In theory this can also be extended to Python classmethod calls.

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.

None yet

4 participants