Skip to content

Commit

Permalink
fixes #16790; fixes #19075; put big arrays on the constant seqs; don'…
Browse files Browse the repository at this point in the history
…t inline them in the VM; big performance boost (#21318)

* don't inline arrays in VM

* add a test for #19075

(cherry picked from commit b5f64f5)
  • Loading branch information
ringabout authored and narimiran committed Apr 26, 2023
1 parent 0fc1b79 commit 7ad8c44
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
7 changes: 5 additions & 2 deletions compiler/vmgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import tables

import
strutils, ast, types, msgs, renderer, vmdef,
strutils, ast, types, msgs, renderer, vmdef, trees,
intsets, magicsys, options, lowerings, lineinfos, transf, astmsgs

from modulegraphs import getBody
Expand Down Expand Up @@ -2073,7 +2073,10 @@ proc gen(c: PCtx; n: PNode; dest: var TDest; flags: TGenFlags = {}) =
genLit(c, n, dest)
of skConst:
let constVal = if s.ast != nil: s.ast else: s.typ.n
gen(c, constVal, dest)
if dontInlineConstant(n, constVal):
genLit(c, constVal, dest)
else:
gen(c, constVal, dest)
of skEnumField:
# we never reach this case - as of the time of this comment,
# skEnumField is folded to an int in semfold.nim, but this code
Expand Down
19 changes: 19 additions & 0 deletions tests/vm/t19075.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
discard """
timeout: 10
joinable: false
"""

# bug #19075
const size = 50_000

const stuff = block:
var a: array[size, int]
a

const zeugs = block:
var zeugs: array[size, int]
for i in 0..<size:
zeugs[i] = stuff[i]
zeugs

doAssert zeugs[0] == 0

0 comments on commit 7ad8c44

Please sign in to comment.