Repository navigation
Commit ff9803a
authored
## 1. property
Add `@vectorcall` to `property.__init__` (the constructor's argument parsing lives there; `tp_new` is `PyType_GenericNew`). There is no change of exception text for bad arguments.
Benchmark:
```
+--------------------------------+--------+------------------------+
| Benchmark | main | patch |
+================================+========+========================+
| property() | 121 ns | 108 ns: 1.12x faster |
| property(f) | 168 ns | 135 ns: 1.24x faster |
+--------------------------------+--------+------------------------+
| Geometric mean | (ref) | 1.18x faster |
+--------------------------------+--------+------------------------+
```
```python
import pyperf
SETUP = """
import builtins
def f(self): pass
property = builtins.property
"""
CASES = [
('property()', 'property()'),
('property(f)', 'property(f)')
]
runner = pyperf.Runner()
for name, stmt in CASES:
runner.timeit(name, stmt=stmt, setup=SETUP)
```
## 2. sentinel
Add `@vectorcall` to `sentinel.__new__`. The keyword-only `repr` parameter means AC routes calls through a helper, but the vectorcall still avoids constructing an argument tuple.
Benchmark:
```
+--------------------------------+--------+------------------------+
| Benchmark | main | patch |
+================================+========+========================+
| sentinel('x') | 158 ns | 116 ns: 1.37x faster |
+--------------------------------+--------+------------------------+
```
```python
import pyperf
SETUP = """
import builtins
sentinel = builtins.sentinel
"""
CASES = [
("sentinel('x')", "sentinel('x')"),
("builtins.sentinel('x')", "builtins.sentinel('x')")
]
runner = pyperf.Runner()
for name, stmt in CASES:
runner.timeit(name, stmt=stmt, setup=SETUP)
```
## 3. typing
Add `@vectorcall` to the `TypeAliasType`, `ParamSpecArgs` and `ParamSpecKwargs` constructors. No change of exception text for bad arguments.
Benchmark:
```
+--------------------------------+--------+------------------------+
| Benchmark | main | patch |
+================================+========+========================+
| TypeAliasType('T', int) | 160 ns | 124 ns: 1.29x faster |
| ParamSpecArgs(ps) | 139 ns | 103 ns: 1.36x faster |
| ParamSpecKwargs(ps) | 133 ns | 102 ns: 1.30x faster |
+--------------------------------+--------+------------------------+
| Geometric mean | (ref) | 1.32x faster |
+--------------------------------+--------+------------------------+
```
```python
import pyperf
SETUP = """
import typing
from typing import TypeAliasType, ParamSpecArgs, ParamSpecKwargs
ps = typing.ParamSpec('P')
"""
CASES = [
("TypeAliasType('T', int)", "TypeAliasType('T', int)"),
('ParamSpecArgs(ps)', 'ParamSpecArgs(ps)'),
('ParamSpecKwargs(ps)', 'ParamSpecKwargs(ps)')
]
runner = pyperf.Runner()
for name, stmt in CASES:
runner.timeit(name, stmt=stmt, setup=SETUP)
```
1 parent 1994e3f commit ff9803a
6 files changed
Lines changed: 239 additions & 43 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments