Skip to content

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

Merged
asvetlov merged 1 commit into
python:mainfrom
tanloong:mappingproxytype_vectorcall
Nov 22, 2026
Merged

asvetlov merged 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)

@asvetlov
asvetlov enabled auto-merge (squash) November 22, 2026 18:17
@asvetlov
asvetlov merged commit 3092f32 into python:main Nov 22, 2026
62 checks passed
@tanloong
tanloong deleted the mappingproxytype_vectorcall branch November 22, 2026 18:20
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