Repository navigation
Commit 5e41a26
gh-87613: Use AC vectorcall for bool
Move bool.__new__ to Argument Clinic with @vectorcall, dropping the
hand-written bool_new and bool_vectorcall. The generated vectorcall name
matches the hand-written one so the tp_vectorcall slot is unchanged, and
argument error messages are unchanged on both paths.
pyperf microbenchmark (PGO+LTO, run serially), no significant change on
the vectorcall path:
| Benchmark | base | bool |
|----------------|:-------:|:---------------------:|
| bool.__new__ | 23.0 ns | 21.7 ns: 1.06x faster |
| bool() | 10.1 ns | 10.4 ns: 1.03x slower |
| bool(int) | 12.2 ns | 12.6 ns: 1.03x slower |
| bool(True) | 11.1 ns | 11.4 ns: 1.03x slower |
| Geometric mean | (ref) | 1.00x slower |
Benchmark hidden because not significant (2): bool(__bool__), bool(list)
Instructions per call (callgrind, inclusive of bool_vectorcall or
bool_new, PGO+LTO):
| Case | base | bool | delta |
|-----------------------|-----:|-----:|------:|
| bool() | 17 | 18 | +1 |
| bool(True) | 20 | 23 | +3 |
| bool(12345) | 53 | 49 | -4 |
| bool([1]) | 50 | 47 | -3 |
| bool.__new__(bool, 1) | 127 | 69 | -58 |
The compiler folds PyObject_IsTrue(Py_False) for bool(), so the default
costs nothing; the small deltas are register allocation. bool.__new__
drops PyArg_UnpackTuple for inline clinic parsing.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>1 parent 6c695bf commit 5e41a26
2 files changed
Lines changed: 96 additions & 44 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | 5 | | |
7 | 6 | | |
8 | 7 | | |
9 | 8 | | |
10 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
11 | 17 | | |
12 | 18 | | |
13 | 19 | | |
| |||
23 | 29 | | |
24 | 30 | | |
25 | 31 | | |
26 | | - | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
27 | 38 | | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
| 39 | + | |
33 | 40 | | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
43 | 45 | | |
44 | 46 | | |
45 | | - | |
46 | | - | |
| 47 | + | |
| 48 | + | |
47 | 49 | | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
| 50 | + | |
| 51 | + | |
55 | 52 | | |
56 | 53 | | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | 54 | | |
66 | 55 | | |
67 | 56 | | |
| |||
107 | 96 | | |
108 | 97 | | |
109 | 98 | | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | 99 | | |
121 | 100 | | |
122 | 101 | | |
| |||
189 | 168 | | |
190 | 169 | | |
191 | 170 | | |
192 | | - | |
| 171 | + | |
193 | 172 | | |
194 | 173 | | |
195 | 174 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments