msg326659 - (view) |
Author: Raymond Hettinger (rhettinger) *  |
Date: 2018-09-28 21:15 |
An arg clinic specification such as p: object(subclass_of='&PyTuple_Type') generates slow code using _PyArg_ParseStack() that has to parse a format string like "O!" to decide to make a type check. Instead, it should directly generate a branch-predictable test for the type check and then call the much quicker function _PyArg_UnpackStack(). See https://github.com/python/cpython/pull/9628 for an example of this change giving a 30% speedup. |
|
|
msg326819 - (view) |
Author: Ammar Askar (ammar2) *  |
Date: 2018-10-01 18:26 |
I've attached a PR that implements this. From the looks of it, there aren't a lot of uses of subclass_of within argument clinic converted functions at the moment. Additionally, most of the places it is used tend to have some non object arguments so a call to _PyArg_ParseStack() gets placed anyway. Attached as part of separate commit in the PR is the conversion of some files over to use the new code. These are mostly just to serve as examples. While converting would still leave a call to ParseStack in most places, I'd like to do some benchmarking and figure out if there is still a benefit. Like you said, the fact that branch-prediction is easier might be useful given that these functions are usually called with the right types of arguments anyway. |
|
|
msg326980 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2018-10-03 15:00 |
Thank you for your PR Ammar. But I work on more general changes. The first step is . With implementing the second step this issue can be closed. |
|
|
msg327012 - (view) |
Author: Ammar Askar (ammar2) *  |
Date: 2018-10-03 20:12 |
Aah, I didn't know that ticket existed. Thanks for the link Serhiy, I'll review your PR instead. Leaving it up to Raymond if he wants to close the issue and use the other one to track this. |
|
|
msg333471 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2019-01-11 14:09 |
PR 9659 is mostly superseded by . But it may contain other changes. Ammar, do you mind to create a new PR or merge the old PR with the current master? |
|
|
msg333494 - (view) |
Author: Ammar Askar (ammar2) *  |
Date: 2019-01-11 17:45 |
Sounds good, I'll take a look at the changes and update the PR accordingly. |
|
|
msg333509 - (view) |
Author: Ammar Askar (ammar2) *  |
Date: 2019-01-12 03:18 |
Great job Serhiy, your work on argument clinic has encompassed the previous PR very well. I've updated it for the changes. |
|
|
msg333512 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2019-01-12 06:23 |
New changeset cb08a71c5c534f33d9486677534dafb087c30e8c by Serhiy Storchaka (Ammar Askar) in branch 'master': bpo-34838: Use subclass_of for math.dist. (GH-9659) https://github.com/python/cpython/commit/cb08a71c5c534f33d9486677534dafb087c30e8c |
|
|