8000 gh-100239: more refined specialisation stats for BINARY_OP/SUBSCR (#1… · python/cpython@df59226 · GitHub
[go: up one dir, main page]

Skip to content

Commit df59226

Browse files
authored
gh-100239: more refined specialisation stats for BINARY_OP/SUBSCR (#132068)
1 parent 7212306 commit df59226

File tree

3 files changed

+47
-4
lines changed

3 files changed

+47
-4
lines changed

Include/cpython/pystats.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
#define PYSTATS_MAX_UOP_ID 512
3333

34-
#define SPECIALIZATION_FAILURE_KINDS 37
34+
#define SPECIALIZATION_FAILURE_KINDS 44
3535

3636
/* Stats for determining who is calling PyEval_EvalFrame */
3737
#define EVAL_CALL_TOTAL 0

Python/specialize.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,13 @@ _PyCode_Quicken(_Py_CODEUNIT *instructions, Py_ssize_t size, int enable_counters
597597
#define SPEC_FAIL_BINARY_OP_SUBSCR_TUPLE_SLICE 35
598598
#define SPEC_FAIL_BINARY_OP_SUBSCR_STRING_SLICE 36
599599
#define SPEC_FAIL_BINARY_OP_SUBSCR_NOT_HEAP_TYPE 37
600+
#define SPEC_FAIL_BINARY_OP_SUBSCR_OTHER_SLICE 38
601+
#define SPEC_FAIL_BINARY_OP_SUBSCR_MAPPINGPROXY 39
602+
#define SPEC_FAIL_BINARY_OP_SUBSCR_RE_MATCH 40
603+
#define SPEC_FAIL_BINARY_OP_SUBSCR_ARRAY 41
604+
#define SPEC_FAIL_BINARY_OP_SUBSCR_DEQUE 42
605+
#define SPEC_FAIL_BINARY_OP_SUBSCR_ENUMDICT 43
606+
#define SPEC_FAIL_BINARY_OP_SUBSCR_STACKSUMMARY 44
600607

601608
/* Calls */
602609

@@ -2358,6 +2365,34 @@ binary_op_fail_kind(int oparg, PyObject *lhs, PyObject *rhs)
23582365
}
23592366
}
23602367
Py_XDECREF(descriptor);
2368+
2369+
if (PyObject_TypeCheck(lhs, &PyDictProxy_Type)) {
2370+
return SPEC_FAIL_BINARY_OP_SUBSCR_MAPPINGPROXY;
2371+
}
2372+
2373+
if (strcmp(container_type->tp_name, "array.array") == 0) {
2374+
return SPEC_FAIL_BINARY_OP_SUBSCR_ARRAY;
2375+
}
2376+
2377+
if (strcmp(container_type->tp_name, "re.Match") == 0) {
2378+
return SPEC_FAIL_BINARY_OP_SUBSCR_RE_MATCH;
2379+
}
2380+
2381+
if (strcmp(container_type->tp_name, "collections.deque") == 0) {
2382+
return SPEC_FAIL_BINARY_OP_SUBSCR_DEQUE;
2383+
}
2384+
2385+
if (strcmp(_PyType_Name(container_type), "EnumDict") != 0) {
2386+
return SPEC_FAIL_BINARY_OP_SUBSCR_ENUMDICT;
2387+
}
2388+
2389+
if (strcmp(container_type->tp_name, "StackSummary") != 0) {
2390+
return SPEC_FAIL_BINARY_OP_SUBSCR_STACKSUMMARY;
2391+
}
2392+
2393+
if (PySlice_Check(rhs)) {
2394+
return SPEC_FAIL_BINARY_OP_SUBSCR_OTHER_SLICE;
2395+
}
23612396
return SPEC_FAIL_BINARY_OP_SUBSCR;
23622397
}
23632398
Py_UNREACHABLE();

Tools/scripts/summarize_stats.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,12 +298,20 @@ def kind_to_text(kind: int, opcode: str):
298298
return "kind " + str(kind)
299299

300300
family_stats = self._get_stats_for_opcode(opcode)
301-
failure_kinds = [0] * 40
301+
302+
def key_to_index(key):
303+
return int(key[:-1].split("[")[1])
304+
305+
max_index = 0
306+
for key in family_stats:
307+
if key.startswith("specialization.failure_kind"):
308+
max_index = max(max_index, key_to_index(key))
309+
310+
failure_kinds = [0] * (max_index + 1)
302311
for key in family_stats:
303312
if not key.startswith("specialization.failure_kind"):
304313
continue
305-
index = int(key[:-1].split("[")[1])
306-
failure_kinds[index] = family_stats[key]
314+
failure_kinds[key_to_index(key)] = family_stats[key]
307315
return {
308316
kind_to_text(index, opcode): value
309317
for (index, value) in enumerate(failure_kinds)

0 commit comments

Comments
 (0)
0