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.

Title: Use PEP 590 vectorcall to speed up calls to filter()
Type: Stage: resolved
Components: Interpreter Core Versions: Python 3.10
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: corona10, rhettinger, vstinner
Priority: normal Keywords: patch

Created on 2021-02-21 17:59 by corona10, last changed 2022-04-11 14:59 by admin. This issue is now closed.

File name Uploaded Description Edit corona10, 2021-02-21 17:59
Pull Requests
URL Status Linked Edit
PR 24611 merged corona10, 2021-02-21 18:02
Messages (7)
msg387469 - (view) Author: Dong-hee Na (corona10) * (Python committer) Date: 2021-02-21 17:59
| Benchmark    | master | vectorcall           |
| bench filter | 191 ns | 151 ns: 1.26x faster |

Like reversed(, it looks okay to update filter() to use PEP 590.
msg387470 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2021-02-21 18:40
+0 I don't see any downside.

Note, the benchmark only times instantiation of the filter object.  It doesn't actually run the iterator which is where most of the runtime cost is spent.  So in actual code there is almost zero benefit.  For example, add "list" to the statement:   stmt="b = list(filter(lambda x: x % 2 == 0, a))" and the improvement disappears.
msg387482 - (view) Author: Dong-hee Na (corona10) * (Python committer) Date: 2021-02-22 00:18
> +0 I don't see any downside.

Thank you Raymond :)
I agree with your view, At first, I thought that instantiation time reducing is also meaningful and we already applied PEP 590 for some of the types to reduce instantiation. (e.g range(), list(), dict(), bool(), reversed(), type()..)

And also I thought that filter is one of the well-used features in Python so it was one of the candidates to apply from my sight. ;)

But if this PR only consume maintenance cost, I am okay with not to apply it doesn't matter :)

And happy new year Raymond(Sorry I am late ;) But the lunar new year was only 2weeks ago so not too late lol)
msg387490 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2021-02-22 03:12
Happy new year to you as well :-)
msg387493 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2021-02-22 03:35
FWIW, I don't think there is much of a maintenance burden; hence, the +0.  You've already done the work.
msg388355 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-03-09 11:34
See also bpo-43447: "Generate vectorcall code to parse arguments using Argument Clinic".
msg388443 - (view) Author: Dong-hee Na (corona10) * (Python committer) Date: 2021-03-10 16:40
New changeset 9a9c11ad41d7887f3d6440e0f0e8966156d959b5 by Dong-hee Na in branch 'master':
bpo-43287: Use PEP 590 vectorcall to speed up filter() (GH-24611)
Date User Action Args
2022-04-11 14:59:41adminsetgithub: 87453
2021-03-10 16:40:19corona10setstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2021-03-10 16:40:03corona10setmessages: + msg388443
2021-03-09 11:34:40vstinnersetmessages: + msg388355
2021-02-22 03:35:33rhettingersetmessages: + msg387493
2021-02-22 03:12:13rhettingersetmessages: + msg387490
2021-02-22 00:18:12corona10setmessages: + msg387482
2021-02-21 18:40:56rhettingersetnosy: + rhettinger
messages: + msg387470
2021-02-21 18:02:22corona10setkeywords: + patch
stage: patch review
pull_requests: + pull_request23390
2021-02-21 17:59:22corona10create