From 09b1eb68ae941438914036c921cd91ed0fc1afe8 Mon Sep 17 00:00:00 2001 From: sergeych Date: Mon, 16 Feb 2026 17:58:05 +0300 Subject: [PATCH] Enable fast string compares for indexed list --- .../kotlin/net/sergeych/lyng/bytecode/BytecodeCompiler.kt | 5 +++++ notes/fast_ops_optimizations_plan.md | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lynglib/src/commonMain/kotlin/net/sergeych/lyng/bytecode/BytecodeCompiler.kt b/lynglib/src/commonMain/kotlin/net/sergeych/lyng/bytecode/BytecodeCompiler.kt index 942dc52..ae90beb 100644 --- a/lynglib/src/commonMain/kotlin/net/sergeych/lyng/bytecode/BytecodeCompiler.kt +++ b/lynglib/src/commonMain/kotlin/net/sergeych/lyng/bytecode/BytecodeCompiler.kt @@ -3533,6 +3533,11 @@ class BytecodeCompiler( val elementClass = listElementClassBySlot[receiver.slot] ?: listElementClassFromReceiverRef(ref.targetRef) if (elementClass != null) { slotObjClass[dst] = elementClass + if (elementClass == ObjString.type && elementClass.isClosed) { + stableObjSlots.add(dst) + } else { + stableObjSlots.remove(dst) + } } return CompiledValue(dst, SlotType.OBJ) } diff --git a/notes/fast_ops_optimizations_plan.md b/notes/fast_ops_optimizations_plan.md index 01df7b9..05a7aa3 100644 --- a/notes/fast_ops_optimizations_plan.md +++ b/notes/fast_ops_optimizations_plan.md @@ -16,7 +16,8 @@ Candidates (not started) 4) Range/loop hot path (done) - Reuse a cached ObjVoid slot for if-statements in statement context (avoids per-iteration CONST_OBJ). - MixedCompareBenchmarkTest: 249 ms -> 247 ms. -5) String ops - - Extend fast path for string comparisons in hot loops. +5) String ops (done) + - Mark GET_INDEX results as stable only for closed ObjString elements to enable fast compares. + - MixedCompareBenchmarkTest: 247 ms -> 240 ms. 6) Box/unbox audit - Identify remaining BOX_OBJ / OBJ_TO_* in inner loops and eliminate when safe.