Repository navigation
Commit 68195ff
gh-162350: Use AC vectorcall for complex()
Generate complex.__new__ and its vectorcall with Argument Clinic. To keep
accepting a string only as a positional argument (complex('1') but not
complex(real='1')), real and imag are declared twice: positional-only and
keyword-only, with @text_signature keeping the visible "(real=0, imag=0)".
The previous hand-written tp_new wrapper becomes the one-argument
conversion called from complex_new_impl().
Error messages change when more than two arguments are passed in total:
a duplicated or unknown keyword is now reported as such instead of
"takes at most 2 arguments (N given)".
Microbenchmarks (pyperf, PGO+LTO):
| Benchmark | main | patch |
|-------------------------------------|:-------:|:---------------------:|
| complex(real=a_float, imag=a_float) | 67.4 ns | 37.9 ns: 1.78x faster |
| complex(a_float, imag=a_float) | 62.2 ns | 39.2 ns: 1.59x faster |
| complex(a_complex) | 18.9 ns | 12.0 ns: 1.57x faster |
| complex(a_float, a_float) | 38.0 ns | 29.2 ns: 1.30x faster |
| complex(an_int) | 36.9 ns | 29.9 ns: 1.24x faster |
| complex(a_float) | 31.0 ns | 26.0 ns: 1.19x faster |
| complex(a_str) | 48.4 ns | 41.8 ns: 1.16x faster |
| complex() | 21.1 ns | 18.5 ns: 1.14x faster |
Subclass construction (no vectorcall) is unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>1 parent 1cc5802 commit 68195ff
3 files changed
Lines changed: 99 additions & 34 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
609 | 609 | | |
610 | 610 | | |
611 | 611 | | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
612 | 616 | | |
613 | 617 | | |
614 | 618 | | |
| |||
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 | |
|---|---|---|---|
| |||
1121 | 1121 | | |
1122 | 1122 | | |
1123 | 1123 | | |
1124 | | - | |
1125 | | - | |
1126 | | - | |
1127 | | - | |
1128 | | - | |
| 1124 | + | |
| 1125 | + | |
| 1126 | + | |
| 1127 | + | |
| 1128 | + | |
1129 | 1129 | | |
1130 | 1130 | | |
1131 | 1131 | | |
1132 | | - | |
| 1132 | + | |
1133 | 1133 | | |
1134 | 1134 | | |
1135 | 1135 | | |
1136 | 1136 | | |
1137 | | - | |
1138 | | - | |
1139 | | - | |
1140 | | - | |
1141 | | - | |
1142 | | - | |
1143 | | - | |
1144 | | - | |
1145 | 1137 | | |
1146 | 1138 | | |
1147 | 1139 | | |
| |||
1190 | 1182 | | |
1191 | 1183 | | |
1192 | 1184 | | |
| 1185 | + | |
1193 | 1186 | | |
| 1187 | + | |
1194 | 1188 | | |
1195 | | - | |
1196 | | - | |
| 1189 | + | |
| 1190 | + | |
| 1191 | + | |
| 1192 | + | |
| 1193 | + | |
| 1194 | + | |
1197 | 1195 | | |
1198 | 1196 | | |
1199 | 1197 | | |
| |||
1204 | 1202 | | |
1205 | 1203 | | |
1206 | 1204 | | |
1207 | | - | |
1208 | | - | |
| 1205 | + | |
| 1206 | + | |
| 1207 | + | |
1209 | 1208 | | |
1210 | 1209 | | |
1211 | 1210 | | |
| |||
1214 | 1213 | | |
1215 | 1214 | | |
1216 | 1215 | | |
| 1216 | + | |
| 1217 | + | |
| 1218 | + | |
| 1219 | + | |
| 1220 | + | |
| 1221 | + | |
| 1222 | + | |
| 1223 | + | |
| 1224 | + | |
| 1225 | + | |
| 1226 | + | |
| 1227 | + | |
| 1228 | + | |
| 1229 | + | |
| 1230 | + | |
| 1231 | + | |
| 1232 | + | |
| 1233 | + | |
| 1234 | + | |
| 1235 | + | |
1217 | 1236 | | |
| 1237 | + | |
| 1238 | + | |
| 1239 | + | |
1218 | 1240 | | |
1219 | 1241 | | |
1220 | 1242 | | |
| |||
1454 | 1476 | | |
1455 | 1477 | | |
1456 | 1478 | | |
1457 | | - | |
| 1479 | + | |
1458 | 1480 | | |
| 1481 | + | |
1459 | 1482 | | |
1460 | 1483 | | |
0 commit comments