[Python-checkins] Include length in stats for UNPACK_SEQUENCE. (GH-31254)
markshannon
webhook-mailer at python.org
Mon Feb 14 05:02:07 EST 2022
https://github.com/python/cpython/commit/15ee55528e1cbc47ef7e9f64186393eee40a49d9
commit: 15ee55528e1cbc47ef7e9f64186393eee40a49d9
branch: main
author: Mark Shannon <mark at hotpy.org>
committer: markshannon <mark at hotpy.org>
date: 2022-02-14T10:01:31Z
summary:
Include length in stats for UNPACK_SEQUENCE. (GH-31254)
files:
M Python/ceval.c
M Python/specialize.c
diff --git a/Python/ceval.c b/Python/ceval.c
index 5eb91502c3010..ad8b05400d564 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -2740,10 +2740,10 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
PREDICTED(UNPACK_SEQUENCE);
PyObject *seq = POP(), *item, **items;
#ifdef Py_STATS
- extern int _PySpecialization_ClassifySequence(PyObject *);
+ extern int _PySpecialization_ClassifySequence(PyObject *, int);
_py_stats.opcode_stats[UNPACK_SEQUENCE].specialization.failure++;
_py_stats.opcode_stats[UNPACK_SEQUENCE].specialization.
- failure_kinds[_PySpecialization_ClassifySequence(seq)]++;
+ failure_kinds[_PySpecialization_ClassifySequence(seq, oparg)]++;
#endif
if (PyTuple_CheckExact(seq) &&
PyTuple_GET_SIZE(seq) == oparg) {
diff --git a/Python/specialize.c b/Python/specialize.c
index 1259a3ca3eccc..b54a2ecd506fc 100644
--- a/Python/specialize.c
+++ b/Python/specialize.c
@@ -602,8 +602,26 @@ initial_counter_value(void) {
#define SPEC_FAIL_FOR_ITER_ENUMERATE 23
/* UNPACK_SEQUENCE */
-#define SPEC_FAIL_UNPACK_SEQUENCE_TUPLE 10
-#define SPEC_FAIL_UNPACK_SEQUENCE_LIST 11
+#define SPEC_FAIL_UNPACK_SEQUENCE_TUPLE_0 9
+#define SPEC_FAIL_UNPACK_SEQUENCE_TUPLE_1 10
+#define SPEC_FAIL_UNPACK_SEQUENCE_TUPLE_2 11
+#define SPEC_FAIL_UNPACK_SEQUENCE_TUPLE_3 12
+#define SPEC_FAIL_UNPACK_SEQUENCE_TUPLE_4 13
+#define SPEC_FAIL_UNPACK_SEQUENCE_TUPLE_N 14
+
+#define SPEC_FAIL_UNPACK_SEQUENCE_LIST_0 15
+#define SPEC_FAIL_UNPACK_SEQUENCE_LIST_1 16
+#define SPEC_FAIL_UNPACK_SEQUENCE_LIST_2 17
+#define SPEC_FAIL_UNPACK_SEQUENCE_LIST_3 18
+#define SPEC_FAIL_UNPACK_SEQUENCE_LIST_4 19
+#define SPEC_FAIL_UNPACK_SEQUENCE_LIST_N 20
+
+#define SPEC_FAIL_UNPACK_SEQUENCE_OTHER_0 21
+#define SPEC_FAIL_UNPACK_SEQUENCE_OTHER_1 22
+#define SPEC_FAIL_UNPACK_SEQUENCE_OTHER_2 23
+#define SPEC_FAIL_UNPACK_SEQUENCE_OTHER_3 24
+#define SPEC_FAIL_UNPACK_SEQUENCE_OTHER_4 25
+#define SPEC_FAIL_UNPACK_SEQUENCE_OTHER_N 26
static int
@@ -1978,15 +1996,19 @@ int
}
int
-_PySpecialization_ClassifySequence(PyObject *seq)
+_PySpecialization_ClassifySequence(PyObject *seq, int n)
{
+ assert(n >= 0);
+ if (n > 4) {
+ n = 5;
+ }
if (PyTuple_CheckExact(seq)) {
- return SPEC_FAIL_UNPACK_SEQUENCE_TUPLE;
+ return SPEC_FAIL_UNPACK_SEQUENCE_TUPLE_0 + n;
}
if (PyList_CheckExact(seq)) {
- return SPEC_FAIL_UNPACK_SEQUENCE_LIST;
+ return SPEC_FAIL_UNPACK_SEQUENCE_LIST_0 + n;
}
- return SPEC_FAIL_OTHER;
+ return SPEC_FAIL_UNPACK_SEQUENCE_OTHER_0 + n;
}
int
More information about the Python-checkins
mailing list