From 4449d8424cde5e2c7715baad45af5c731547fd1f Mon Sep 17 00:00:00 2001 From: Sacul0457Deve <183588943+Sacul0457@users.noreply.github.com.> Date: Sun, 8 Feb 2026 09:05:05 +0800 Subject: [PATCH 1/2] optimise _ITER_CHECK_RANGE and _ITER_CHECK_LIST --- Python/optimizer_bytecodes.c | 14 ++++++++++++++ Python/optimizer_cases.c.h | 12 ++++++++++++ 2 files changed, 26 insertions(+) diff --git a/Python/optimizer_bytecodes.c b/Python/optimizer_bytecodes.c index 0863d5dd8f8df7..3c2be7c8d617a0 100644 --- a/Python/optimizer_bytecodes.c +++ b/Python/optimizer_bytecodes.c @@ -1088,6 +1088,20 @@ dummy_func(void) { sym_set_type(iter, &PyTuple_Type); } + op(_ITER_CHECK_LIST, (iter, null_or_index -- iter, null_or_index)) { + if (sym_matches_type(iter, &PyList_Type)) { + ADD_OP(_NOP, 0, 0); + } + sym_set_type(iter, &PyList_Type); + } + + op(_ITER_CHECK_RANGE, (iter, null_or_index -- iter, null_or_index)) { + if (sym_matches_type(iter, &PyRange_Type)) { + ADD_OP(_NOP, 0, 0); + } + sym_set_type(iter, &PyRange_Type); + } + op(_ITER_NEXT_RANGE, (iter, null_or_index -- iter, null_or_index, next)) { next = sym_new_type(ctx, &PyLong_Type); } diff --git a/Python/optimizer_cases.c.h b/Python/optimizer_cases.c.h index 9a51d2fa366661..84ef9228dbb36a 100644 --- a/Python/optimizer_cases.c.h +++ b/Python/optimizer_cases.c.h @@ -2621,6 +2621,12 @@ /* _INSTRUMENTED_FOR_ITER is not a viable micro-op for tier 2 */ case _ITER_CHECK_LIST: { + JitOptRef iter; + iter = stack_pointer[-2]; + if (sym_matches_type(iter, &PyList_Type)) { + ADD_OP(_NOP, 0, 0); + } + sym_set_type(iter, &PyList_Type); break; } @@ -2669,6 +2675,12 @@ } case _ITER_CHECK_RANGE: { + JitOptRef iter; + iter = stack_pointer[-2]; + if (sym_matches_type(iter, &PyRange_Type)) { + ADD_OP(_NOP, 0, 0); + } + sym_set_type(iter, &PyRange_Type); break; } From 1490bd8d7201a1e5fdb5f277cfe60d9ad682c7eb Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Sun, 8 Feb 2026 01:19:51 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2026-02-08-01-19-50.gh-issue-131798.PaWDNH.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2026-02-08-01-19-50.gh-issue-131798.PaWDNH.rst diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-02-08-01-19-50.gh-issue-131798.PaWDNH.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-02-08-01-19-50.gh-issue-131798.PaWDNH.rst new file mode 100644 index 00000000000000..fe80c2d911b6ee --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2026-02-08-01-19-50.gh-issue-131798.PaWDNH.rst @@ -0,0 +1 @@ +Optimize ``_ITER_CHECK_RANGE`` and ``_ITER_CHECK_LIST`` in the JIT