Open juancarlospaco opened 1 week ago
!nim c --gc:orc -d:useMalloc
iterator myPairsInline*[T](twoDarray: seq[seq[T]]): (int, seq[T]) {.inline.} =
for indexValuePair in twoDarray.pairs:
yield indexValuePair
iterator myPairsClosure*[T](twoDarray: seq[seq[T]]): (int, seq[T]) {.closure.} =
for indexValuePair in twoDarray.pairs:
yield indexValuePair
template testTotalMem(iter: untyped): int =
proc innerTestTotalMem(): int {.gensym.} =
result = 0
# do the same operation 100 times, which should have similar mem footprint
# as doing it once.
for iterNum in 0..100:
result = max(result, getTotalMem()) # record current mem footprint
# initialize nested sequence
var my2dArray: seq[seq[int32]] = @[]
# fill with some data...
for i in 0'i32..10_000:
var z = @[i, i+1]
my2dArray.add z
# use that data somehow...
var otherContainer: seq[int32] = @[]
var count = 0'i32
for oneDindex, innerArray in my2dArray.iter:
for value in innerArray:
inc count
if oneDindex > 50 and value < 200:
otherContainer.add count
innerTestTotalMem()
proc main =
let closureMem = testTotalMem(myPairsClosure) #1052672
let inlineMem = testTotalMem(myPairsInline) #20328448
when defined(echoFootprint):
echo "Closure memory footprint: " & $closureMem
echo "Inline memory footprint: " & $inlineMem
# check that mem footprint is relatively similar b/t each method
doAssert (closureMem - inlineMem).abs < (closureMem div 10)
main()
436.55 Kb (447,024 bytes)
Duration 24 mins
453.46 Kb (464,344 bytes)
Duration 23 mins
486.11 Kb (497,776 bytes)
Duration 24 mins
434.13 Kb (444,552 bytes)
Duration 24 mins
437.91 Kb (448,416 bytes)
Duration 22 mins
437.91 Kb (448,416 bytes)
Duration
437.91 Kb (448,416 bytes)
Duration
437.91 Kb (448,416 bytes)
Duration
11.4.0
14.0.0
20.4
2024-11-10T18:33:37Z
1
nim c --gc:orc -d:useMalloc -d:nimArcDebug -d:nimArcIds -d:nimAllocPagesViaMalloc -d:useSysAssert -d:useGcAssert -d:nimLeakDetector --debugger:native --debuginfo:on -d:nimDebug -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --lineTrace:off --nimcache:/home/runner/work/nimrun-action-minefield/nimrun-action-minefield --out:/home/runner/work/nimrun-action-minefield/nimrun-action-minefield/temp /home/runner/work/nimrun-action-minefield/nimrun-action-minefield/temp.nim && valgrind /home/runner/work/nimrun-action-minefield/nimrun-action-minefield/temp
:robot: Bug found in 33 mins
bisecting 8
commits at 0
commits per second
TESTING ONLY.