Skip to content

gh-162350: Use AC vectorcall for itertools.product / zip_longest - #162663

Open
tanloong wants to merge 4 commits into
python:mainfrom
tanloong:product_ziplongest_vectorcall
Open

tanloong wants to merge 4 commits into
python:mainfrom
tanloong:product_ziplongest_vectorcall

Conversation

@tanloong

@tanloong tanloong commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Replace hand-written constructors with AC + vectorcall.

product(..., repeat=1, bad='a') now raises TypeError: got an unexpected keyword argument 'bad' instead of TypeError: takes at most 1 keyword argument (2 given).

zip_longest(..., bad='a') now raises TypeError: zip_longest() got an unexpected keyword argument 'bad' instead of TypeError: zip_longest() got an unexpected keyword argument. Other error text for bad argument is unchanged.

Benchmark:

+----------------+--------+----------------------+
| Benchmark      | main   | patch                |
+================+========+======================+
| product(x)     | 215 ns | 177 ns: 1.22x faster |
+----------------+--------+----------------------+
| zip_longest(x) | 221 ns | 194 ns: 1.14x faster |
+----------------+--------+----------------------+
| Geometric mean | (ref)  | 1.18x faster         |
+----------------+--------+----------------------+
Details
import pyperf

SETUP = """
import itertools
x = [1, 2, 3]
"""

CASES = [
    ('product(x)', 'itertools.product(x)'),
    ('zip_longest(x)', 'itertools.zip_longest(x)')
]

runner = pyperf.Runner()
for name, stmt in CASES:
    runner.timeit(name, stmt=stmt, setup=SETUP)

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants