Skip to content

gh-162350: Add AC vectorcall for string.templatelib - #162452

Open
tanloong wants to merge 1 commit into
python:mainfrom
tanloong:templatelib_vectorcall
Open

tanloong wants to merge 1 commit into
python:mainfrom
tanloong:templatelib_vectorcall

Conversation

@tanloong

@tanloong tanloong commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Add AC vectorcall for Template and Interpolation.

Template now raises TypeError: Template() takes no keyword arguments for kwargs instead of TypeError: Template.__new__ only accepts *args arguments.

Benchmark:

+--------------------------------+--------+------------------------+
| Benchmark                      | main   | patch                  |
+================================+========+========================+
| Template('a')                  | 177 ns | 134 ns: 1.32x faster   |
| Interpolation(1)               | 148 ns | 105 ns: 1.41x faster   |
+--------------------------------+--------+------------------------+
| Geometric mean                 | (ref)  | 1.36x faster           |
+--------------------------------+--------+------------------------+
Details
import pyperf

SETUP = """
from string.templatelib import Template, Interpolation
"""

CASES = [
    ("Template('a')", "Template('a')"),
    ('Interpolation(1)', 'Interpolation(1)')
]

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.

1 participant