Issue 29029: Faster positional arguments parsing in PyArg_ParseTupleAndKeywords (original) (raw)

Created on 2016-12-20 21:30 by serhiy.storchaka, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
PyArg_ParseTupleAndKeywords-faster-positional-args-parse.patch serhiy.storchaka,2016-12-20 21:30 review
PyArg_ParseTupleAndKeywords-faster-positional-args-parse-2.patch vstinner,2017-01-16 23:39 review
Messages (8)
msg283711 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-12-20 21:30
Proposed patch speeds up parsing positional arguments in PyArg_ParseTupleAndKeywords(). $ ./python -m perf timeit "1 .to_bytes(1, 'little', signed=False)" Unpatched: Median +- std dev: 2.01 us +- 0.09 us Patched: Median +- std dev: 1.23 us +- 0.03 us Currently names of all passed positional argument are looked up in the kwargs dictionary for checking if the argument is passed as positional and keyword argument. With the patch this is checked only if there are unhandled keyword arguments after parsing keyword arguments that don't passed as positional arguments. The same optimization also is applied to _PyArg_ParseTupleAndKeywordsFast() and like, but the effect is much smaller. The patch also includes tiny refactoring.
msg285515 - (view) Author: Inada Naoki (methane) * (Python committer) Date: 2017-01-15 17:25
LGTM
msg285590 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2017-01-16 23:39
New changeset a36e60c5fee0 by Victor Stinner in branch 'default': Rename keywords to kwargs in getargs.c https://hg.python.org/cpython/rev/a36e60c5fee0
msg285591 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-01-16 23:39
Oh, I missed this issue. Since I made minor cleanup recently, I took the liberty of rebasing your patch. I also pushed your "keywords => kwargs" change, just to make the patch simpler to review.
msg285592 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-01-16 23:49
> Unpatched: Median +- std dev: 2.01 us +- 0.09 us > Patched: Median +- std dev: 1.23 us +- 0.03 us Oh wow, impressive speedup! As usual, good job Serhiy ;-) PyArg_ParseTupleAndKeywords-faster-positional-args-parse-2.patch: LGTM! Can you please push it?
msg285617 - (view) Author: Inada Naoki (methane) * (Python committer) Date: 2017-01-17 07:24
LGTM again.
msg285621 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2017-01-17 08:07
New changeset a8563ef0eb8a by Serhiy Storchaka in branch 'default': Issue #29029: Speed up processing positional arguments in https://hg.python.org/cpython/rev/a8563ef0eb8a
msg285622 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-01-17 08:15
Thank you for your reviews Inada and Victor. Thank you for rebasing the patch Victor. I were going first to try an alternative patch, maybe less efficient, but allowing to share more code. But since the code is changed so fast, it is better to commit the ready patch.
History
Date User Action Args
2022-04-11 14:58:40 admin set github: 73215
2017-01-17 08:15:00 serhiy.storchaka set status: open -> closedresolution: fixedmessages: + stage: patch review -> resolved
2017-01-17 08:07:56 python-dev set messages: +
2017-01-17 07:24:59 methane set messages: +
2017-01-16 23:49:18 vstinner set messages: +
2017-01-16 23:39:55 vstinner set files: + PyArg_ParseTupleAndKeywords-faster-positional-args-parse-2.patchnosy: + vstinnermessages: +
2017-01-16 23:39:01 python-dev set nosy: + python-devmessages: +
2017-01-15 17:25:56 methane set nosy: + methanemessages: +
2016-12-20 21:30:18 serhiy.storchaka create