fixes #19728; setLen slow when shrinking seq due to zero-filling of released area (#24683)

fixes #19728

don't zero-filling memory for "trivial types" without destructor in
refc. I tested locally with internal apis.

(cherry picked from commit b421d0f8ee)
This commit is contained in:
ringabout
2025-02-27 23:45:58 +08:00
committed by narimiran
parent 5394c6814b
commit fcf4f10c70
3 changed files with 40 additions and 4 deletions

View File

@@ -1925,6 +1925,13 @@ proc genArrayLen(p: BProc, e: PNode, d: var TLoc, op: TMagic) =
else: putIntoDest(p, d, e, rope(lengthOrd(p.config, typ)))
else: internalError(p.config, e.info, "genArrayLen()")
proc isTrivialTypesToSnippet(t: PType): Rope =
if containsGarbageCollectedRef(t) or
hasDestructor(t):
result = rope"NIM_FALSE"
else:
result = rope"NIM_TRUE"
proc genSetLengthSeq(p: BProc, e: PNode, d: var TLoc) =
if optSeqDestructors in p.config.globalOptions:
e[1] = makeAddr(e[1], p.module.idgen)
@@ -1945,10 +1952,11 @@ proc genSetLengthSeq(p: BProc, e: PNode, d: var TLoc) =
genTypeInfoV1(p.module, t.skipTypes(abstractInst), e.info)])
else:
const setLenPattern = "($3) #setLengthSeqV2($1, $4, $2)"
const setLenPattern = "($3) #setLengthSeqV2($1, $4, $2, $5)"
call.snippet = ropecg(p.module, setLenPattern, [
rdLoc(a), rdLoc(b), getTypeDesc(p.module, t),
genTypeInfoV1(p.module, t.skipTypes(abstractInst), e.info)])
genTypeInfoV1(p.module, t.skipTypes(abstractInst), e.info),
isTrivialTypesToSnippet(t.skipTypes(abstractInst)[0])])
genAssignment(p, a, call, {})
gcUsage(p.config, e)