-
-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
bpo-45885: Add more stats for COMPARE_OP in specialize.c #31040
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Added more fined-grained specialization failure stats regarding the ``COMPARE_OP`` bytecode. |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -533,6 +533,14 @@ initial_counter_value(void) { | |||||
#define SPEC_FAIL_STRING_COMPARE 13 | ||||||
#define SPEC_FAIL_NOT_FOLLOWED_BY_COND_JUMP 14 | ||||||
#define SPEC_FAIL_BIG_INT 15 | ||||||
#define SPEC_FAIL_COMPARE_BYTES 16 | ||||||
#define SPEC_FAIL_COMPARE_TUPLE 17 | ||||||
#define SPEC_FAIL_COMPARE_LIST 18 | ||||||
#define SPEC_FAIL_COMPARE_SET 19 | ||||||
#define SPEC_FAIL_COMPARE_BOOL 20 | ||||||
#define SPEC_FAIL_COMPARE_BASEOBJECT 21 | ||||||
#define SPEC_FAIL_COMPARE_FLOAT_LONG 22 | ||||||
#define SPEC_FAIL_COMPARE_LONG_FLOAT 23 | ||||||
|
||||||
static int | ||||||
specialize_module_load_attr( | ||||||
|
@@ -1764,6 +1772,16 @@ _Py_Specialize_CompareOp(PyObject *lhs, PyObject *rhs, | |||||
when_to_jump_mask = (1 | 2 | 4) & ~when_to_jump_mask; | ||||||
} | ||||||
if (Py_TYPE(lhs) != Py_TYPE(rhs)) { | ||||||
#ifdef Py_STATS | ||||||
if (PyFloat_CheckExact(lhs) && PyLong_CheckExact(rhs)) { | ||||||
SPECIALIZATION_FAIL(COMPARE_OP, SPEC_FAIL_COMPARE_FLOAT_LONG); | ||||||
goto failure; | ||||||
} | ||||||
if (PyLong_CheckExact(lhs) && PyFloat_CheckExact(rhs)) { | ||||||
SPECIALIZATION_FAIL(COMPARE_OP, SPEC_FAIL_COMPARE_LONG_FLOAT); | ||||||
goto failure; | ||||||
} | ||||||
#endif | ||||||
SPECIALIZATION_FAIL(COMPARE_OP, SPEC_FAIL_DIFFERENT_TYPES); | ||||||
goto failure; | ||||||
} | ||||||
|
@@ -1794,6 +1812,32 @@ _Py_Specialize_CompareOp(PyObject *lhs, PyObject *rhs, | |||||
goto success; | ||||||
} | ||||||
} | ||||||
#ifdef Py_STATS | ||||||
if (PyBytes_CheckExact(lhs)) { | ||||||
SPECIALIZATION_FAIL(COMPARE_OP, SPEC_FAIL_COMPARE_BYTES); | ||||||
goto failure; | ||||||
} | ||||||
if (PyTuple_CheckExact(lhs)) { | ||||||
SPECIALIZATION_FAIL(COMPARE_OP, SPEC_FAIL_COMPARE_TUPLE); | ||||||
goto failure; | ||||||
} | ||||||
if (PyList_CheckExact(lhs)) { | ||||||
SPECIALIZATION_FAIL(COMPARE_OP, SPEC_FAIL_COMPARE_LIST); | ||||||
goto failure; | ||||||
} | ||||||
if (PySet_CheckExact(lhs) || PyFrozenSet_CheckExact(lhs)) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd personally rather not -- IMO the |
||||||
SPECIALIZATION_FAIL(COMPARE_OP, SPEC_FAIL_COMPARE_SET); | ||||||
goto failure; | ||||||
} | ||||||
if (PyBool_Check(lhs)) { | ||||||
SPECIALIZATION_FAIL(COMPARE_OP, SPEC_FAIL_COMPARE_BOOL); | ||||||
goto failure; | ||||||
} | ||||||
if (Py_TYPE(lhs)->tp_richcompare == PyBaseObject_Type.tp_richcompare) { | ||||||
SPECIALIZATION_FAIL(COMPARE_OP, SPEC_FAIL_COMPARE_BASEOBJECT); | ||||||
goto failure; | ||||||
} | ||||||
#endif | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As above, could you move the classification of the failure into a helper function? |
||||||
SPECIALIZATION_FAIL(COMPARE_OP, SPEC_FAIL_OTHER); | ||||||
failure: | ||||||
STAT_INC(COMPARE_OP, failure); | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you rewrite this as
SPECIALIZATION_FAIL(COMPARE_OP, compare_op_fail_kind(lhs, rhs));
following the pattern used in the other specialization functions?