From c8e6b059a4378f75569e3dd1a8ae356b1f1a574a Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Thu, 9 Apr 2026 17:07:04 +0800 Subject: [PATCH] optimizes `setLen` for orc; disabling overflow checks (#25722) ref https://github.com/nim-lang/Nim/issues/25695 ref https://github.com/nim-lang/Nim/pull/25715 This pull request introduces a minor but important change to the `setLen` procedure in `lib/system/seqs_v2.nim`. The main update is the temporary disabling of overflow checks during the initialization loop when extending the sequence length, which can improve performance and avoid unnecessary checks during this operation. Memory and performance improvement: * Disabled overflow checks for the loop that initializes new elements to their default value when increasing the length of a sequence in `setLen`, by wrapping the loop with `{.push overflowChecks: off.}` and `{.pop.}`. --- lib/system/seqs_v2.nim | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/system/seqs_v2.nim b/lib/system/seqs_v2.nim index fefb6e914c..511bb87d82 100644 --- a/lib/system/seqs_v2.nim +++ b/lib/system/seqs_v2.nim @@ -262,8 +262,11 @@ proc setLen[T](s: var seq[T], newlen: Natural) {.nodestroy.} = if xu.p == nil or (xu.p.cap and not strlitFlag) < newlen: xu.p = cast[typeof(xu.p)](prepareSeqAddUninit(oldLen, xu.p, newlen - oldLen, sizeof(T), alignof(T))) xu.len = newlen + + {.push overflowChecks: off.} for i in oldLen..