Uh oh!
There was an error while loading. Please reload this page.
gh-90350: Optimize builtin functions min() and max() - #30286
Conversation
This comment has been minimized.
This comment has been minimized.
colorfulappl
commented
Dec 30, 2021
I wrote an "Argument Clinic" version here: But seems it is not as fast as current "without Argument Clinic" version: Result of microbench:
On the most commonly used case, "max(a, b [, ...])", there is not noticeable speed up when we use AC, especially when multiple arguments are passed (the last case). I noticed that in 9af34c9 , the varargs on stack are packed to tuple before passed to callee, and callee obtains each argument by access the tuple's elements. |
colorfulappl
commented
Dec 30, 2021
One goal of IMHO, the process of pack/unpack arguments to a tuple is unnecessary in 9af34c9 . I would have a try, then may open another issue if necessary. |
Yes, such a change demands a separate issue / PR. It would be nice if you could add proof-of-concept benchmark results when you present the idea in the new bpo issue. I can add the relevant core devs on the nosy list, if you want. Keep in mind that readability and maintainability weigh very heavy when considering a PR; that also goes for optimisation changes. |
While that change certainly looks better, it is buggy; it does not heed the key function. With that in mind, the benchmarks you posted in #30286 (comment) are obviously wrong; the benchmarks with the |
sweeneyde
commented
Dec 30, 2021
I wonder if Argument Clinic Itself could be updated to convert |
sweeneyde
commented
Dec 31, 2021
@isidentical any thoughts on removing the tuple creation in some cases, or with some flag? |
This comment was marked as off-topic.
This comment was marked as off-topic.
I opened a new issue (gh-903701), Footnotes
|
colorfulappl
commented
Dec 31, 2021
Thanks for revising my mistake. I'v seen the new results after your amend. |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
eendebakpt
commented
Jul 16, 2023
@colorfulappl Is this PR still blocked by #90370? |
Summary: Builtin functions min() and max() now use METH_FASTCALL upstream issue: python/cpython#90350 upstream PR: python/cpython#30286 upstream commit: python/cpython@0066ab5 Reviewed By: carljm Differential Revision: D52650071 fbshipit-source-id: 93971e865ab9515efc9771c58582f63d15e0342d
…30286) Builtin functions min() and max() now use METH_FASTCALL
…30286) Builtin functions min() and max() now use METH_FASTCALL
Builtin functions min() and max() are labeled as METH_VARARGS | METH_KEYWORDS, which use tp_call calling convention.
After changing their label to METH_FASTCALL | METH_KEYWORDS, they can be invoked by vectorcall.
This optimization simplifies parameter passing and avoids creation of temporary tuple while parsing arguments, brings about up to 200%+ speed up on microbenchmarks.
faster-cpython/ideas#199
https://bugs.python.org/issue46192