Repository navigation
Commit a32f37e
authored
pythongh-162350: Add AC vectorcall for operator.itemgetter / attrgetter (python#162486)
Replace hand-written `itemgetter` and `attrgetter` with Argument Clinic + vectorcall. Rename with `as itemgetter_type_new` and `as attrgetter_type_new` to avoid conflict between the generated `<name>_vectorcall` name and the existing instance-call vectorcall. There is not bad argument message change.
Benchmark:
```
+-----------------+--------+----------------------+
| Benchmark | main | patch |
+=================+========+======================+
| itemgetter(0) | 136 ns | 109 ns: 1.25x faster |
+-----------------+--------+----------------------+
| attrgetter("x") | 162 ns | 135 ns: 1.20x faster |
+-----------------+--------+----------------------+
| Geometric mean | (ref) | 1.22x faster |
+-----------------+--------+----------------------+
```
```python
import pyperf
SETUP = """
import operator
class C:
x = 1
c = C()
"""
CASES = [
('itemgetter(0)', 'operator.itemgetter(0)'),
('attrgetter("x")', 'operator.attrgetter("x")')
]
runner = pyperf.Runner()
for name, stmt in CASES:
runner.timeit(name, stmt=stmt, setup=SETUP)
```1 parent 4f74347 commit a32f37e
2 files changed
Lines changed: 152 additions & 28 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
31 | 41 | | |
32 | 42 | | |
33 | 43 | | |
| |||
1029 | 1039 | | |
1030 | 1040 | | |
1031 | 1041 | | |
1032 | | - | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
1033 | 1049 | | |
1034 | | - | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
1035 | 1053 | | |
1036 | 1054 | | |
1037 | 1055 | | |
1038 | | - | |
1039 | 1056 | | |
1040 | 1057 | | |
1041 | | - | |
| 1058 | + | |
| 1059 | + | |
1042 | 1060 | | |
1043 | | - | |
1044 | | - | |
1045 | | - | |
1046 | | - | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
1047 | 1068 | | |
1048 | | - | |
1049 | | - | |
| 1069 | + | |
1050 | 1070 | | |
1051 | 1071 | | |
1052 | 1072 | | |
1053 | 1073 | | |
1054 | 1074 | | |
| 1075 | + | |
1055 | 1076 | | |
1056 | 1077 | | |
1057 | 1078 | | |
1058 | | - | |
1059 | | - | |
| 1079 | + | |
| 1080 | + | |
1060 | 1081 | | |
1061 | 1082 | | |
1062 | 1083 | | |
| |||
1225 | 1246 | | |
1226 | 1247 | | |
1227 | 1248 | | |
1228 | | - | |
| 1249 | + | |
| 1250 | + | |
1229 | 1251 | | |
1230 | 1252 | | |
1231 | 1253 | | |
| |||
1257 | 1279 | | |
1258 | 1280 | | |
1259 | 1281 | | |
1260 | | - | |
| 1282 | + | |
| 1283 | + | |
| 1284 | + | |
| 1285 | + | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + | |
1261 | 1289 | | |
1262 | | - | |
| 1290 | + | |
| 1291 | + | |
| 1292 | + | |
1263 | 1293 | | |
1264 | 1294 | | |
1265 | 1295 | | |
1266 | | - | |
| 1296 | + | |
1267 | 1297 | | |
1268 | | - | |
| 1298 | + | |
| 1299 | + | |
1269 | 1300 | | |
1270 | | - | |
1271 | | - | |
1272 | | - | |
1273 | | - | |
1274 | | - | |
1275 | 1301 | | |
1276 | 1302 | | |
1277 | | - | |
| 1303 | + | |
1278 | 1304 | | |
1279 | 1305 | | |
1280 | 1306 | | |
1281 | 1307 | | |
1282 | 1308 | | |
1283 | | - | |
1284 | | - | |
| 1309 | + | |
| 1310 | + | |
1285 | 1311 | | |
1286 | 1312 | | |
1287 | 1313 | | |
| |||
1359 | 1385 | | |
1360 | 1386 | | |
1361 | 1387 | | |
1362 | | - | |
| 1388 | + | |
1363 | 1389 | | |
1364 | 1390 | | |
1365 | 1391 | | |
| |||
1592 | 1618 | | |
1593 | 1619 | | |
1594 | 1620 | | |
1595 | | - | |
| 1621 | + | |
| 1622 | + | |
1596 | 1623 | | |
1597 | 1624 | | |
1598 | 1625 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments