classification
Title: Speed up _PyArg_NoKeywords() and like
Type: performance Stage: resolved
Components: Interpreter Core Versions: Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: python-dev, rhettinger, serhiy.storchaka, vstinner
Priority: normal Keywords: patch

Created on 2017-02-06 08:09 by serhiy.storchaka, last changed 2017-02-06 09:47 by vstinner. This issue is now closed.

Files
File name Uploaded Description Edit
_PyArg_NoKeywords_macro.patch serhiy.storchaka, 2017-02-06 08:09 review
Messages (7)
msg287098 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-02-06 08:09
Proposed patch makes _PyArg_NoKeywords(), _PyArg_NoStackKeywords() and _PyArg_NoPositional() macros. This eliminates the overhead of the cross-module function call in common case.

This idea was previously discussed in issue26822 and raised again in issue29452.
msg287104 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2017-02-06 08:32
+1
msg287105 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2017-02-06 08:42
New changeset 82d1c8d15e18 by Serhiy Storchaka in branch 'default':
Issue #29460: _PyArg_NoKeywords(), _PyArg_NoStackKeywords() and
https://hg.python.org/cpython/rev/82d1c8d15e18
msg287106 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-02-06 08:50
Oh right, I recall that I proposed it. Thanks for this change :-)

The next question might it: would it be worth it to try using unlikely() macro on (kwargs == NULL) test in the macro? ;-)

I'm talking about GCC/Clang __builtin_expect:

#define unlikely(x)     __builtin_expect((x),0)
msg287110 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2017-02-06 09:00
New changeset f5ef851ff6b26529382747cfea4674158c7c1ebc by Serhiy Storchaka in branch 'master':
Issue #29460: _PyArg_NoKeywords(), _PyArg_NoStackKeywords() and
https://github.com/python/cpython/commit/f5ef851ff6b26529382747cfea4674158c7c1ebc
msg287111 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-02-06 09:13
> The next question might it: would it be worth it to try using unlikely()
> macro on (kwargs == NULL) test in the macro? ;-)

Perhaps this may help in some critical tight loops (in implementations of 
dict, string operations or long integer arithmetic), but I doubt it can have 
any measurable effect when used once per a call of a function calling 
PyArg_Parse* and using many other stuff.
msg287114 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-02-06 09:47
I created the issue #29461: "Experiment usage of likely/unlikely in CPython core".
History
Date User Action Args
2017-02-06 09:47:13vstinnersetmessages: + msg287114
2017-02-06 09:13:28serhiy.storchakasetmessages: + msg287111
2017-02-06 09:00:23python-devsetmessages: + msg287110
2017-02-06 08:50:04vstinnersetmessages: + msg287106
2017-02-06 08:42:42serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2017-02-06 08:42:12python-devsetnosy: + python-dev
messages: + msg287105
2017-02-06 08:32:57rhettingersetmessages: + msg287104
2017-02-06 08:09:51serhiy.storchakacreate