Skip to content

gh-162350: Add AC vectorcall for mappingproxy.__new__ to speed up types.MappingProxyType - #162430

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

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

Conversation

@tanloong

@tanloong tanloong commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Add @vectorcall to mappingproxy.__new__. There is no change of exception text for bad arguments.

Benchmark:

+---------------------------+--------+-----------------------+
| Benchmark                 | main   | patch                 |
+===========================+========+=======================+
| MappingProxyType(d)       | 134 ns | 90.8 ns: 1.48x faster |
+---------------------------+--------+-----------------------+
| types.MappingProxyType(d) | 143 ns | 98.7 ns: 1.45x faster |
+---------------------------+--------+-----------------------+
| Geometric mean            | (ref)  | 1.46x faster          |
+---------------------------+--------+-----------------------+
Details
import pyperf

SETUP = """
import sys
import types
from types import MappingProxyType

def f(self):
    pass

class C:
    def m(self):
        pass

obj = C()
code = f.__code__
gns = globals()
d = {}
frame = sys._getframe()
"""

CASES = [
    ("MappingProxyType(d)", "MappingProxyType(d)"),
    ("types.MappingProxyType(d)", "types.MappingProxyType(d)"),
]


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