Skip to content

Commit

Permalink
Collect stats for UNPACK_SEQUENCE. (GH-31105)
Browse files Browse the repository at this point in the history
  • Loading branch information
markshannon authored Feb 3, 2022
1 parent da4d4ec commit a0401d8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
6 changes: 6 additions & 0 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -2792,6 +2792,12 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
TARGET(UNPACK_SEQUENCE) {
PREDICTED(UNPACK_SEQUENCE);
PyObject *seq = POP(), *item, **items;
#ifdef Py_STATS
extern int _PySpecialization_ClassifySequence(PyObject *);
_py_stats.opcode_stats[UNPACK_SEQUENCE].specialization.failure++;
_py_stats.opcode_stats[UNPACK_SEQUENCE].specialization.
failure_kinds[_PySpecialization_ClassifySequence(seq)]++;
#endif
if (PyTuple_CheckExact(seq) &&
PyTuple_GET_SIZE(seq) == oparg) {
items = ((PyTupleObject *)seq)->ob_item;
Expand Down
17 changes: 16 additions & 1 deletion Python/specialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,10 @@ initial_counter_value(void) {
#define SPEC_FAIL_ITER_DICT_VALUES 22
#define SPEC_FAIL_ITER_ENUMERATE 23

/* UNPACK_SEQUENCE */
#define SPEC_FAIL_TUPLE 10
#define SPEC_FAIL_LIST 11


static int
specialize_module_load_attr(
Expand Down Expand Up @@ -1880,7 +1884,6 @@ _Py_Specialize_CompareOp(PyObject *lhs, PyObject *rhs,
adaptive->counter = initial_counter_value();
}


int
_PySpecialization_ClassifyIterator(PyObject *iter)
{
Expand Down Expand Up @@ -1930,3 +1933,15 @@ int
}
return SPEC_FAIL_OTHER;
}

int
_PySpecialization_ClassifySequence(PyObject *seq)
{
if (PyTuple_CheckExact(seq)) {
return SPEC_FAIL_TUPLE;
}
if (PyList_CheckExact(seq)) {
return SPEC_FAIL_LIST;
}
return SPEC_FAIL_OTHER;
}

0 comments on commit a0401d8

Please sign in to comment.