Skip to content

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

Closed
Fidget-Spinner wants to merge 6 commits into
python:mainfrom
Fidget-Spinner:classmethod_unbound_only
Closed

bpo-45295: Speed up C classmethod calls via unbound classmethods#28572
Fidget-Spinner wants to merge 6 commits into
python:mainfrom
Fidget-Spinner:classmethod_unbound_only

Conversation

@Fidget-Spinner

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

Copy link
Copy Markdown
Member
  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
Copy Markdown
Member Author

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 September 27, 2021 10:10
@Fidget-Spinner

Copy link
Copy Markdown
Member Author

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
Copy Markdown
Member Author

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
Copy Markdown
Member

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

@Fidget-Spinner

Fidget-Spinner commented Oct 18, 2021

Copy link
Copy Markdown
Member Author

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.

5 participants