gh-90350: Optimize builtin functions min() and max()#30286
gh-90350: Optimize builtin functions min() and max()#30286serhiy-storchaka merged 6 commits intopython:mainfrom
Conversation
This comment has been minimized.
This comment has been minimized.
|
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. |
|
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 |
|
I wonder if Argument Clinic Itself could be updated to convert |
|
@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
|
Thanks for revising my mistake. I'v seen the new results after your amend. |
|
@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