Skip to content

gh-87613: Use AC and AC vectorcall for filter - #160792

Open
cmaloney wants to merge 1 commit into
python:mainfrom
cmaloney:ac_vc_filter
Open

cmaloney wants to merge 1 commit into
python:mainfrom
cmaloney:ac_vc_filter

Conversation

@cmaloney

@cmaloney cmaloney commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Move filter.__new__ to Argument Clinic with @vectorcall, dropping the hand-written filter_new and filter_vectorcall. The performance delta is within noise on my machine.

pyperf microbenchmark (PGO+LTO, run serially), no significant change on the vectorcall path:

Benchmark base filter
filter.__new__ 45.4 ns 42.7 ns: 1.06x faster
filter(bool, list) 32.3 ns 32.8 ns: 1.01x slower
filter(None, range) 30.6 ns 31.8 ns: 1.04x slower
Geometric mean (ref) 1.01x faster

Benchmark hidden because not significant (3): subclass(None, tuple), filter(None, tuple), list(filter(None, list))

Move filter.__new__ to Argument Clinic with @vectorcall, dropping the
hand-written filter_new and filter_vectorcall. The generated vectorcall
name matches the hand-written one so the tp_vectorcall slot is unchanged,
and argument error messages are unchanged on both paths.

pyperf microbenchmark (PGO+LTO, run serially), no significant change on
the vectorcall path:

| Benchmark           | base    | filter                |
|---------------------|:-------:|:---------------------:|
| `filter.__new__`    | 45.4 ns | 42.7 ns: 1.06x faster |
| filter(bool, list)  | 32.3 ns | 32.8 ns: 1.01x slower |
| filter(None, range) | 30.6 ns | 31.8 ns: 1.04x slower |
| Geometric mean      | (ref)   | 1.01x faster          |

Benchmark hidden because not significant (3): subclass(None, tuple),
filter(None, tuple), list(filter(None, list))

filter.__new__ drops PyArg_UnpackTuple for inline clinic parsing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@msullivan msullivan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice cleanup

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting merge skip news type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants