Skip to content

bpo-46072: Include length in stats for UNPACK_SEQUENCE. #31254

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -2734,10 +2734,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) {
Expand Down
34 changes: 28 additions & 6 deletions Python/specialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -598,8 +598,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
Expand Down Expand Up @@ -1974,15 +1992,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
Expand Down