From 21eb40cf16bf6811ba0d3a17fccd945746e65efb Mon Sep 17 00:00:00 2001 From: Brandt Bucher Date: Thu, 11 Nov 2021 11:42:33 -0800 Subject: [PATCH 1/4] Specialize unicode formatting --- Include/opcode.h | 67 +++++++++++++++++++++-------------------- Lib/opcode.py | 1 + Python/ceval.c | 28 ++++++++++++----- Python/opcode_targets.h | 14 ++++----- Python/specialize.c | 22 +++++++++++--- 5 files changed, 80 insertions(+), 52 deletions(-) diff --git a/Include/opcode.h b/Include/opcode.h index c7354de9a0687c..c57a7b451a6de8 100644 --- a/Include/opcode.h +++ b/Include/opcode.h @@ -118,39 +118,40 @@ extern "C" { #define BINARY_OP_INPLACE_ADD_UNICODE 16 #define BINARY_OP_MULTIPLY_INT 17 #define BINARY_OP_MULTIPLY_FLOAT 18 -#define BINARY_SUBSCR_ADAPTIVE 19 -#define BINARY_SUBSCR_LIST_INT 20 -#define BINARY_SUBSCR_TUPLE_INT 21 -#define BINARY_SUBSCR_DICT 22 -#define CALL_FUNCTION_ADAPTIVE 23 -#define CALL_FUNCTION_BUILTIN_O 24 -#define CALL_FUNCTION_BUILTIN_FAST 26 -#define CALL_FUNCTION_LEN 27 -#define CALL_FUNCTION_ISINSTANCE 28 -#define CALL_FUNCTION_PY_SIMPLE 29 -#define JUMP_ABSOLUTE_QUICK 34 -#define LOAD_ATTR_ADAPTIVE 36 -#define LOAD_ATTR_INSTANCE_VALUE 38 -#define LOAD_ATTR_WITH_HINT 39 -#define LOAD_ATTR_SLOT 40 -#define LOAD_ATTR_MODULE 41 -#define LOAD_GLOBAL_ADAPTIVE 42 -#define LOAD_GLOBAL_MODULE 43 -#define LOAD_GLOBAL_BUILTIN 44 -#define LOAD_METHOD_ADAPTIVE 45 -#define LOAD_METHOD_CACHED 46 -#define LOAD_METHOD_CLASS 47 -#define LOAD_METHOD_MODULE 48 -#define LOAD_METHOD_NO_DICT 55 -#define STORE_ATTR_ADAPTIVE 56 -#define STORE_ATTR_INSTANCE_VALUE 57 -#define STORE_ATTR_SLOT 58 -#define STORE_ATTR_WITH_HINT 59 -#define LOAD_FAST__LOAD_FAST 62 -#define STORE_FAST__LOAD_FAST 63 -#define LOAD_FAST__LOAD_CONST 64 -#define LOAD_CONST__LOAD_FAST 65 -#define STORE_FAST__STORE_FAST 66 +#define BINARY_OP_REMAINDER_UNICODE 19 +#define BINARY_SUBSCR_ADAPTIVE 20 +#define BINARY_SUBSCR_LIST_INT 21 +#define BINARY_SUBSCR_TUPLE_INT 22 +#define BINARY_SUBSCR_DICT 23 +#define CALL_FUNCTION_ADAPTIVE 24 +#define CALL_FUNCTION_BUILTIN_O 26 +#define CALL_FUNCTION_BUILTIN_FAST 27 +#define CALL_FUNCTION_LEN 28 +#define CALL_FUNCTION_ISINSTANCE 29 +#define CALL_FUNCTION_PY_SIMPLE 34 +#define JUMP_ABSOLUTE_QUICK 36 +#define LOAD_ATTR_ADAPTIVE 38 +#define LOAD_ATTR_INSTANCE_VALUE 39 +#define LOAD_ATTR_WITH_HINT 40 +#define LOAD_ATTR_SLOT 41 +#define LOAD_ATTR_MODULE 42 +#define LOAD_GLOBAL_ADAPTIVE 43 +#define LOAD_GLOBAL_MODULE 44 +#define LOAD_GLOBAL_BUILTIN 45 +#define LOAD_METHOD_ADAPTIVE 46 +#define LOAD_METHOD_CACHED 47 +#define LOAD_METHOD_CLASS 48 +#define LOAD_METHOD_MODULE 55 +#define LOAD_METHOD_NO_DICT 56 +#define STORE_ATTR_ADAPTIVE 57 +#define STORE_ATTR_INSTANCE_VALUE 58 +#define STORE_ATTR_SLOT 59 +#define STORE_ATTR_WITH_HINT 62 +#define LOAD_FAST__LOAD_FAST 63 +#define STORE_FAST__LOAD_FAST 64 +#define LOAD_FAST__LOAD_CONST 65 +#define LOAD_CONST__LOAD_FAST 66 +#define STORE_FAST__STORE_FAST 67 #define DO_TRACING 255 #ifdef NEED_OPCODE_JUMP_TABLES static uint32_t _PyOpcode_RelativeJump[8] = { diff --git a/Lib/opcode.py b/Lib/opcode.py index 940e169d5597d7..b23e930ce88b22 100644 --- a/Lib/opcode.py +++ b/Lib/opcode.py @@ -231,6 +231,7 @@ def jabs_op(name, op): "BINARY_OP_INPLACE_ADD_UNICODE", "BINARY_OP_MULTIPLY_INT", "BINARY_OP_MULTIPLY_FLOAT", + "BINARY_OP_REMAINDER_UNICODE", "BINARY_SUBSCR_ADAPTIVE", "BINARY_SUBSCR_LIST_INT", "BINARY_SUBSCR_TUPLE_INT", diff --git a/Python/ceval.c b/Python/ceval.c index 030d98396780b8..a03e16465d1858 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -4687,14 +4687,6 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr res = PyNumber_Multiply(lhs, rhs); break; case NB_REMAINDER: - if (PyUnicode_CheckExact(lhs) && - (!PyUnicode_Check(rhs) || PyUnicode_CheckExact(rhs))) - { - // bpo-28598: Fast path for string formatting (but not - // if the RHS is a str subclass). - res = PyUnicode_Format(lhs, rhs); - break; - } res = PyNumber_Remainder(lhs, rhs); break; case NB_OR: @@ -4785,6 +4777,26 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr } } + TARGET(BINARY_OP_REMAINDER_UNICODE) { + PyObject *lhs = SECOND(); + PyObject *rhs = TOP(); + DEOPT_IF(!PyUnicode_CheckExact(lhs), BINARY_OP); + DEOPT_IF(!PyUnicode_CheckExact(rhs) && PyUnicode_Check(rhs), + BINARY_OP); + STAT_INC(BINARY_OP, hit); + // bpo-28598: Fast path for string formatting (but not if rhs is a + // str subclass). + PyObject *res = PyUnicode_Format(lhs, rhs); + if (res == NULL) { + goto error; + } + STACK_SHRINK(1); + Py_DECREF(lhs); + Py_DECREF(rhs); + SET_TOP(res); + DISPATCH(); + } + TARGET(EXTENDED_ARG) { int oldoparg = oparg; NEXTOPARG(); diff --git a/Python/opcode_targets.h b/Python/opcode_targets.h index a57617e022e1db..14481a640cb83b 100644 --- a/Python/opcode_targets.h +++ b/Python/opcode_targets.h @@ -18,25 +18,26 @@ static void *opcode_targets[256] = { &&TARGET_BINARY_OP_INPLACE_ADD_UNICODE, &&TARGET_BINARY_OP_MULTIPLY_INT, &&TARGET_BINARY_OP_MULTIPLY_FLOAT, + &&TARGET_BINARY_OP_REMAINDER_UNICODE, &&TARGET_BINARY_SUBSCR_ADAPTIVE, &&TARGET_BINARY_SUBSCR_LIST_INT, &&TARGET_BINARY_SUBSCR_TUPLE_INT, &&TARGET_BINARY_SUBSCR_DICT, &&TARGET_CALL_FUNCTION_ADAPTIVE, - &&TARGET_CALL_FUNCTION_BUILTIN_O, &&TARGET_BINARY_SUBSCR, + &&TARGET_CALL_FUNCTION_BUILTIN_O, &&TARGET_CALL_FUNCTION_BUILTIN_FAST, &&TARGET_CALL_FUNCTION_LEN, &&TARGET_CALL_FUNCTION_ISINSTANCE, - &&TARGET_CALL_FUNCTION_PY_SIMPLE, &&TARGET_GET_LEN, &&TARGET_MATCH_MAPPING, &&TARGET_MATCH_SEQUENCE, &&TARGET_MATCH_KEYS, - &&TARGET_JUMP_ABSOLUTE_QUICK, + &&TARGET_CALL_FUNCTION_PY_SIMPLE, &&TARGET_PUSH_EXC_INFO, - &&TARGET_LOAD_ATTR_ADAPTIVE, + &&TARGET_JUMP_ABSOLUTE_QUICK, &&TARGET_POP_EXCEPT_AND_RERAISE, + &&TARGET_LOAD_ATTR_ADAPTIVE, &&TARGET_LOAD_ATTR_INSTANCE_VALUE, &&TARGET_LOAD_ATTR_WITH_HINT, &&TARGET_LOAD_ATTR_SLOT, @@ -47,26 +48,25 @@ static void *opcode_targets[256] = { &&TARGET_LOAD_METHOD_ADAPTIVE, &&TARGET_LOAD_METHOD_CACHED, &&TARGET_LOAD_METHOD_CLASS, - &&TARGET_LOAD_METHOD_MODULE, &&TARGET_WITH_EXCEPT_START, &&TARGET_GET_AITER, &&TARGET_GET_ANEXT, &&TARGET_BEFORE_ASYNC_WITH, &&TARGET_BEFORE_WITH, &&TARGET_END_ASYNC_FOR, + &&TARGET_LOAD_METHOD_MODULE, &&TARGET_LOAD_METHOD_NO_DICT, &&TARGET_STORE_ATTR_ADAPTIVE, &&TARGET_STORE_ATTR_INSTANCE_VALUE, &&TARGET_STORE_ATTR_SLOT, - &&TARGET_STORE_ATTR_WITH_HINT, &&TARGET_STORE_SUBSCR, &&TARGET_DELETE_SUBSCR, + &&TARGET_STORE_ATTR_WITH_HINT, &&TARGET_LOAD_FAST__LOAD_FAST, &&TARGET_STORE_FAST__LOAD_FAST, &&TARGET_LOAD_FAST__LOAD_CONST, &&TARGET_LOAD_CONST__LOAD_FAST, &&TARGET_STORE_FAST__STORE_FAST, - &&_unknown_opcode, &&TARGET_GET_ITER, &&TARGET_GET_YIELD_FROM_ITER, &&TARGET_PRINT_EXPR, diff --git a/Python/specialize.c b/Python/specialize.c index 7e72013cd8359a..5131570d8395b2 100644 --- a/Python/specialize.c +++ b/Python/specialize.c @@ -1380,13 +1380,13 @@ _Py_Specialize_BinaryOp(PyObject *lhs, PyObject *rhs, _Py_CODEUNIT *instr, SpecializedCacheEntry *cache) { _PyAdaptiveEntry *adaptive = &cache->adaptive; - if (!Py_IS_TYPE(lhs, Py_TYPE(rhs))) { - SPECIALIZATION_FAIL(BINARY_OP, SPEC_FAIL_DIFFERENT_TYPES); - goto failure; - } switch (adaptive->original_oparg) { case NB_ADD: case NB_INPLACE_ADD: + if (!Py_IS_TYPE(lhs, Py_TYPE(rhs))) { + SPECIALIZATION_FAIL(BINARY_OP, SPEC_FAIL_DIFFERENT_TYPES); + goto failure; + } if (PyUnicode_CheckExact(lhs)) { if (_Py_OPCODE(instr[1]) == STORE_FAST && Py_REFCNT(lhs) == 2) { *instr = _Py_MAKECODEUNIT(BINARY_OP_INPLACE_ADD_UNICODE, @@ -1409,6 +1409,10 @@ _Py_Specialize_BinaryOp(PyObject *lhs, PyObject *rhs, _Py_CODEUNIT *instr, break; case NB_MULTIPLY: case NB_INPLACE_MULTIPLY: + if (!Py_IS_TYPE(lhs, Py_TYPE(rhs))) { + SPECIALIZATION_FAIL(BINARY_OP, SPEC_FAIL_DIFFERENT_TYPES); + goto failure; + } if (PyLong_CheckExact(lhs)) { *instr = _Py_MAKECODEUNIT(BINARY_OP_MULTIPLY_INT, _Py_OPARG(*instr)); @@ -1420,6 +1424,16 @@ _Py_Specialize_BinaryOp(PyObject *lhs, PyObject *rhs, _Py_CODEUNIT *instr, goto success; } break; + case NB_REMAINDER: + case NB_INPLACE_REMAINDER: + if (PyUnicode_CheckExact(lhs) && + (PyUnicode_CheckExact(rhs) || !PyUnicode_Check(rhs))) + { + *instr = _Py_MAKECODEUNIT(BINARY_OP_REMAINDER_UNICODE, + _Py_OPARG(*instr)); + goto success; + } + break; default: // These operators don't have any available specializations. Rather // than repeatedly attempting to specialize them, just convert them From 1d57dbaafc8423b80a5132e2f3096d616f467d7e Mon Sep 17 00:00:00 2001 From: Brandt Bucher Date: Thu, 11 Nov 2021 19:12:31 -0800 Subject: [PATCH 2/4] blurb add --- .../Core and Builtins/2021-11-11-19-11-57.bpo-45636.2fyIVm.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2021-11-11-19-11-57.bpo-45636.2fyIVm.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2021-11-11-19-11-57.bpo-45636.2fyIVm.rst b/Misc/NEWS.d/next/Core and Builtins/2021-11-11-19-11-57.bpo-45636.2fyIVm.rst new file mode 100644 index 00000000000000..d7eeb4849ebc89 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2021-11-11-19-11-57.bpo-45636.2fyIVm.rst @@ -0,0 +1,2 @@ +Convert old-style string formatting optimizations into specialized +instructions. From 6ffcf47863d33be888e3807daa871c2367faf174 Mon Sep 17 00:00:00 2001 From: Brandt Bucher Date: Fri, 12 Nov 2021 09:32:14 -0800 Subject: [PATCH 3/4] Remove BINARY_OP_REMAINDER_UNICODE --- Include/opcode.h | 67 ++++++++++++++++++++--------------------- Lib/opcode.py | 1 - Python/ceval.c | 20 ------------ Python/opcode_targets.h | 14 ++++----- Python/specialize.c | 10 ------ 5 files changed, 40 insertions(+), 72 deletions(-) diff --git a/Include/opcode.h b/Include/opcode.h index c57a7b451a6de8..c7354de9a0687c 100644 --- a/Include/opcode.h +++ b/Include/opcode.h @@ -118,40 +118,39 @@ extern "C" { #define BINARY_OP_INPLACE_ADD_UNICODE 16 #define BINARY_OP_MULTIPLY_INT 17 #define BINARY_OP_MULTIPLY_FLOAT 18 -#define BINARY_OP_REMAINDER_UNICODE 19 -#define BINARY_SUBSCR_ADAPTIVE 20 -#define BINARY_SUBSCR_LIST_INT 21 -#define BINARY_SUBSCR_TUPLE_INT 22 -#define BINARY_SUBSCR_DICT 23 -#define CALL_FUNCTION_ADAPTIVE 24 -#define CALL_FUNCTION_BUILTIN_O 26 -#define CALL_FUNCTION_BUILTIN_FAST 27 -#define CALL_FUNCTION_LEN 28 -#define CALL_FUNCTION_ISINSTANCE 29 -#define CALL_FUNCTION_PY_SIMPLE 34 -#define JUMP_ABSOLUTE_QUICK 36 -#define LOAD_ATTR_ADAPTIVE 38 -#define LOAD_ATTR_INSTANCE_VALUE 39 -#define LOAD_ATTR_WITH_HINT 40 -#define LOAD_ATTR_SLOT 41 -#define LOAD_ATTR_MODULE 42 -#define LOAD_GLOBAL_ADAPTIVE 43 -#define LOAD_GLOBAL_MODULE 44 -#define LOAD_GLOBAL_BUILTIN 45 -#define LOAD_METHOD_ADAPTIVE 46 -#define LOAD_METHOD_CACHED 47 -#define LOAD_METHOD_CLASS 48 -#define LOAD_METHOD_MODULE 55 -#define LOAD_METHOD_NO_DICT 56 -#define STORE_ATTR_ADAPTIVE 57 -#define STORE_ATTR_INSTANCE_VALUE 58 -#define STORE_ATTR_SLOT 59 -#define STORE_ATTR_WITH_HINT 62 -#define LOAD_FAST__LOAD_FAST 63 -#define STORE_FAST__LOAD_FAST 64 -#define LOAD_FAST__LOAD_CONST 65 -#define LOAD_CONST__LOAD_FAST 66 -#define STORE_FAST__STORE_FAST 67 +#define BINARY_SUBSCR_ADAPTIVE 19 +#define BINARY_SUBSCR_LIST_INT 20 +#define BINARY_SUBSCR_TUPLE_INT 21 +#define BINARY_SUBSCR_DICT 22 +#define CALL_FUNCTION_ADAPTIVE 23 +#define CALL_FUNCTION_BUILTIN_O 24 +#define CALL_FUNCTION_BUILTIN_FAST 26 +#define CALL_FUNCTION_LEN 27 +#define CALL_FUNCTION_ISINSTANCE 28 +#define CALL_FUNCTION_PY_SIMPLE 29 +#define JUMP_ABSOLUTE_QUICK 34 +#define LOAD_ATTR_ADAPTIVE 36 +#define LOAD_ATTR_INSTANCE_VALUE 38 +#define LOAD_ATTR_WITH_HINT 39 +#define LOAD_ATTR_SLOT 40 +#define LOAD_ATTR_MODULE 41 +#define LOAD_GLOBAL_ADAPTIVE 42 +#define LOAD_GLOBAL_MODULE 43 +#define LOAD_GLOBAL_BUILTIN 44 +#define LOAD_METHOD_ADAPTIVE 45 +#define LOAD_METHOD_CACHED 46 +#define LOAD_METHOD_CLASS 47 +#define LOAD_METHOD_MODULE 48 +#define LOAD_METHOD_NO_DICT 55 +#define STORE_ATTR_ADAPTIVE 56 +#define STORE_ATTR_INSTANCE_VALUE 57 +#define STORE_ATTR_SLOT 58 +#define STORE_ATTR_WITH_HINT 59 +#define LOAD_FAST__LOAD_FAST 62 +#define STORE_FAST__LOAD_FAST 63 +#define LOAD_FAST__LOAD_CONST 64 +#define LOAD_CONST__LOAD_FAST 65 +#define STORE_FAST__STORE_FAST 66 #define DO_TRACING 255 #ifdef NEED_OPCODE_JUMP_TABLES static uint32_t _PyOpcode_RelativeJump[8] = { diff --git a/Lib/opcode.py b/Lib/opcode.py index b23e930ce88b22..940e169d5597d7 100644 --- a/Lib/opcode.py +++ b/Lib/opcode.py @@ -231,7 +231,6 @@ def jabs_op(name, op): "BINARY_OP_INPLACE_ADD_UNICODE", "BINARY_OP_MULTIPLY_INT", "BINARY_OP_MULTIPLY_FLOAT", - "BINARY_OP_REMAINDER_UNICODE", "BINARY_SUBSCR_ADAPTIVE", "BINARY_SUBSCR_LIST_INT", "BINARY_SUBSCR_TUPLE_INT", diff --git a/Python/ceval.c b/Python/ceval.c index a03e16465d1858..29e464ceac6e21 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -4777,26 +4777,6 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr } } - TARGET(BINARY_OP_REMAINDER_UNICODE) { - PyObject *lhs = SECOND(); - PyObject *rhs = TOP(); - DEOPT_IF(!PyUnicode_CheckExact(lhs), BINARY_OP); - DEOPT_IF(!PyUnicode_CheckExact(rhs) && PyUnicode_Check(rhs), - BINARY_OP); - STAT_INC(BINARY_OP, hit); - // bpo-28598: Fast path for string formatting (but not if rhs is a - // str subclass). - PyObject *res = PyUnicode_Format(lhs, rhs); - if (res == NULL) { - goto error; - } - STACK_SHRINK(1); - Py_DECREF(lhs); - Py_DECREF(rhs); - SET_TOP(res); - DISPATCH(); - } - TARGET(EXTENDED_ARG) { int oldoparg = oparg; NEXTOPARG(); diff --git a/Python/opcode_targets.h b/Python/opcode_targets.h index 14481a640cb83b..a57617e022e1db 100644 --- a/Python/opcode_targets.h +++ b/Python/opcode_targets.h @@ -18,26 +18,25 @@ static void *opcode_targets[256] = { &&TARGET_BINARY_OP_INPLACE_ADD_UNICODE, &&TARGET_BINARY_OP_MULTIPLY_INT, &&TARGET_BINARY_OP_MULTIPLY_FLOAT, - &&TARGET_BINARY_OP_REMAINDER_UNICODE, &&TARGET_BINARY_SUBSCR_ADAPTIVE, &&TARGET_BINARY_SUBSCR_LIST_INT, &&TARGET_BINARY_SUBSCR_TUPLE_INT, &&TARGET_BINARY_SUBSCR_DICT, &&TARGET_CALL_FUNCTION_ADAPTIVE, - &&TARGET_BINARY_SUBSCR, &&TARGET_CALL_FUNCTION_BUILTIN_O, + &&TARGET_BINARY_SUBSCR, &&TARGET_CALL_FUNCTION_BUILTIN_FAST, &&TARGET_CALL_FUNCTION_LEN, &&TARGET_CALL_FUNCTION_ISINSTANCE, + &&TARGET_CALL_FUNCTION_PY_SIMPLE, &&TARGET_GET_LEN, &&TARGET_MATCH_MAPPING, &&TARGET_MATCH_SEQUENCE, &&TARGET_MATCH_KEYS, - &&TARGET_CALL_FUNCTION_PY_SIMPLE, - &&TARGET_PUSH_EXC_INFO, &&TARGET_JUMP_ABSOLUTE_QUICK, - &&TARGET_POP_EXCEPT_AND_RERAISE, + &&TARGET_PUSH_EXC_INFO, &&TARGET_LOAD_ATTR_ADAPTIVE, + &&TARGET_POP_EXCEPT_AND_RERAISE, &&TARGET_LOAD_ATTR_INSTANCE_VALUE, &&TARGET_LOAD_ATTR_WITH_HINT, &&TARGET_LOAD_ATTR_SLOT, @@ -48,25 +47,26 @@ static void *opcode_targets[256] = { &&TARGET_LOAD_METHOD_ADAPTIVE, &&TARGET_LOAD_METHOD_CACHED, &&TARGET_LOAD_METHOD_CLASS, + &&TARGET_LOAD_METHOD_MODULE, &&TARGET_WITH_EXCEPT_START, &&TARGET_GET_AITER, &&TARGET_GET_ANEXT, &&TARGET_BEFORE_ASYNC_WITH, &&TARGET_BEFORE_WITH, &&TARGET_END_ASYNC_FOR, - &&TARGET_LOAD_METHOD_MODULE, &&TARGET_LOAD_METHOD_NO_DICT, &&TARGET_STORE_ATTR_ADAPTIVE, &&TARGET_STORE_ATTR_INSTANCE_VALUE, &&TARGET_STORE_ATTR_SLOT, + &&TARGET_STORE_ATTR_WITH_HINT, &&TARGET_STORE_SUBSCR, &&TARGET_DELETE_SUBSCR, - &&TARGET_STORE_ATTR_WITH_HINT, &&TARGET_LOAD_FAST__LOAD_FAST, &&TARGET_STORE_FAST__LOAD_FAST, &&TARGET_LOAD_FAST__LOAD_CONST, &&TARGET_LOAD_CONST__LOAD_FAST, &&TARGET_STORE_FAST__STORE_FAST, + &&_unknown_opcode, &&TARGET_GET_ITER, &&TARGET_GET_YIELD_FROM_ITER, &&TARGET_PRINT_EXPR, diff --git a/Python/specialize.c b/Python/specialize.c index 5131570d8395b2..cfc21bf70ad6be 100644 --- a/Python/specialize.c +++ b/Python/specialize.c @@ -1424,16 +1424,6 @@ _Py_Specialize_BinaryOp(PyObject *lhs, PyObject *rhs, _Py_CODEUNIT *instr, goto success; } break; - case NB_REMAINDER: - case NB_INPLACE_REMAINDER: - if (PyUnicode_CheckExact(lhs) && - (PyUnicode_CheckExact(rhs) || !PyUnicode_Check(rhs))) - { - *instr = _Py_MAKECODEUNIT(BINARY_OP_REMAINDER_UNICODE, - _Py_OPARG(*instr)); - goto success; - } - break; default: // These operators don't have any available specializations. Rather // than repeatedly attempting to specialize them, just convert them From b37bf5aff6860de8b441ef50a806dadc8dc45678 Mon Sep 17 00:00:00 2001 From: Brandt Bucher Date: Fri, 12 Nov 2021 14:10:25 -0800 Subject: [PATCH 4/4] Update NEWS --- .../2021-11-11-19-11-57.bpo-45636.2fyIVm.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Misc/NEWS.d/next/Core and Builtins/2021-11-11-19-11-57.bpo-45636.2fyIVm.rst b/Misc/NEWS.d/next/Core and Builtins/2021-11-11-19-11-57.bpo-45636.2fyIVm.rst index d7eeb4849ebc89..f705b41fd8c2d0 100644 --- a/Misc/NEWS.d/next/Core and Builtins/2021-11-11-19-11-57.bpo-45636.2fyIVm.rst +++ b/Misc/NEWS.d/next/Core and Builtins/2021-11-11-19-11-57.bpo-45636.2fyIVm.rst @@ -1,2 +1,2 @@ -Convert old-style string formatting optimizations into specialized -instructions. +Remove an existing "fast path" for old-style string formatting, since +it no longer appears to have any measurable impact.