You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Faster positional arguments parsing in PyArg_ParseTupleAndKeywords #73215
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.
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.
Activity
serhiy-storchaka commentedon Dec 20, 2016
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 usCurrently 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.
methane commentedon Jan 15, 2017
LGTM
python-dev commentedon Jan 16, 2017
New changeset a36e60c5fee0 by Victor Stinner in branch 'default':
Rename keywords to kwargs in getargs.c
https://hg.python.org/cpython/rev/a36e60c5fee0
vstinner commentedon Jan 16, 2017
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.
vstinner commentedon Jan 16, 2017
Oh wow, impressive speedup! As usual, good job Serhiy ;-)
PyArg_ParseTupleAndKeywords-faster-positional-args-parse-2.patch: LGTM! Can you please push it?
methane commentedon Jan 17, 2017
LGTM again.
python-dev commentedon Jan 17, 2017
New changeset a8563ef0eb8a by Serhiy Storchaka in branch 'default':
Issue bpo-29029: Speed up processing positional arguments in
https://hg.python.org/cpython/rev/a8563ef0eb8a
serhiy-storchaka commentedon Jan 17, 2017
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.