Repository navigation
Commit 3522677
authored
Replace hand-written `contextvar_tp_new` with Argument Clinic + vectorcall.
Extra positional arguments now raise `TypeError: ContextVar() takes exactly 1 positional argument (N given)` instead of `TypeError: ContextVar() takes at most 1 positional argument (N given)`.
Benchmark:
```
+--------------------------------+--------+------------------------+
| Benchmark | main | patch |
+================================+========+========================+
| ContextVar('x') | 175 ns | 104 ns: 1.69x faster |
| contextvars.ContextVar('x') | 192 ns | 112 ns: 1.72x faster |
+--------------------------------+--------+------------------------+
| Geometric mean | (ref) | 1.70x faster |
+--------------------------------+--------+------------------------+
```
```python
import pyperf
SETUP = """
import contextvars
ContextVar = contextvars.ContextVar
"""
CASES = [
("ContextVar('x')", "ContextVar('x')"),
("contextvars.ContextVar('x')", "contextvars.ContextVar('x')")
]
runner = pyperf.Runner()
for name, stmt in CASES:
runner.timeit(name, stmt=stmt, setup=SETUP)
```
1 parent 0890d65 commit 3522677
2 files changed
Lines changed: 100 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
994 | 994 | | |
995 | 995 | | |
996 | 996 | | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
997 | 1007 | | |
998 | | - | |
| 1008 | + | |
| 1009 | + | |
999 | 1010 | | |
1000 | | - | |
1001 | | - | |
1002 | | - | |
1003 | | - | |
1004 | | - | |
1005 | | - | |
1006 | | - | |
1007 | | - | |
1008 | | - | |
1009 | | - | |
1010 | 1011 | | |
1011 | 1012 | | |
1012 | 1013 | | |
| |||
1200 | 1201 | | |
1201 | 1202 | | |
1202 | 1203 | | |
| 1204 | + | |
1203 | 1205 | | |
1204 | 1206 | | |
1205 | 1207 | | |
| |||
0 commit comments