This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Convert int.__round__ to Argument Clinic
Type: performance Stage: resolved
Components: Argument Clinic, Interpreter Core Versions: Python 3.10
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: larry, mark.dickinson, rhettinger, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2020-07-19 12:38 by serhiy.storchaka, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 21549 merged serhiy.storchaka, 2020-07-19 12:43
Messages (4)
msg373963 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2020-07-19 12:38
int.__round__ was not converted to Argument Clinic because it is not impossible to express a correct signature for it in Python. But now we can at least make Argument Clinic not producing incorrect signature. And converting to Argument Clinic has a performance benefit.

$ ./python -m pyperf timeit -q --compare-to=../cpython-baseline/python "round(12345)"
Mean +- std dev: [/home/serhiy/py/cpython-baseline/python] 123 ns +- 6 ns -> [/home/serhiy/py/cpython-release/python] 94.4 ns +- 2.4 ns: 1.31x faster (-23%)

$ ./python -m pyperf timeit -q --compare-to=../cpython-baseline/python "round(12345, 0)"
Mean +- std dev: [/home/serhiy/py/cpython-baseline/python] 159 ns +- 4 ns -> [/home/serhiy/py/cpython-release/python] 98.6 ns +- 2.4 ns: 1.61x faster (-38%)

$ ./python -m pyperf timeit -q --compare-to=../cpython-baseline/python "round(12345, -2)"
Mean +- std dev: [/home/serhiy/py/cpython-baseline/python] 585 ns +- 9 ns -> [/home/serhiy/py/cpython-release/python] 534 ns +- 14 ns: 1.09x faster (-9%)
msg373977 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2020-07-19 23:58
I don't have an opinion on the PR but want to point-out the Argument Clinic itself doesn't provide a performance benefit.  Anything that it does can also be done directly by the code itself, including vectorcall logic.  You should be able to optimize the function calls without using the Argument Clinic.

That said, it would be great if someone were to work on building-out AC to support more interesting argument patterns like those in round().  Ideally, AC would provide complete, correct support right out of the box.
msg373982 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2020-07-20 04:14
Yes, you can do this without Argument Clinic, but Argument Clinic allows to hide the use of unstable private API and cumbersome code under macros and in generated files.

> That said, it would be great if someone were to work on building-out AC to support more interesting argument patterns like those in round().

The problem is not only in Argument Clinic (and the Argument Clinic part is mainly solved). The problem is that currently it is not possible to express the signature of int.__round__() (and dict.get(), and getattr()) in Python syntax, and the inspect module does not support any non-Python syntax for this either. Once we invent the way to express it, supporting it in Argument Clinic will be merely technical problem.
msg374006 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2020-07-20 12:57
New changeset 5a2bac7fe0e7a2b67fd57c7a9176a50feed0d7a0 by Serhiy Storchaka in branch 'master':
bpo-41342: Convert int.__round__ to Argument Clinic (GH-21549)
https://github.com/python/cpython/commit/5a2bac7fe0e7a2b67fd57c7a9176a50feed0d7a0
History
Date User Action Args
2022-04-11 14:59:33adminsetgithub: 85514
2020-07-20 12:58:03serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2020-07-20 12:57:40serhiy.storchakasetmessages: + msg374006
2020-07-20 04:14:20serhiy.storchakasetmessages: + msg373982
2020-07-19 23:58:29rhettingersetmessages: + msg373977
2020-07-19 23:57:08rhettingersetmessages: - msg373973
2020-07-19 21:32:07rhettingersetnosy: + rhettinger
messages: + msg373973
2020-07-19 15:10:26mark.dickinsonsetnosy: + mark.dickinson
2020-07-19 12:43:07serhiy.storchakasetkeywords: + patch
stage: patch review
pull_requests: + pull_request20691
2020-07-19 12:38:29serhiy.storchakacreate