You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following benchmark program (seq-mazefun) executes pretty quickly in MLton, but after compiling with Manticore it has runaway memory usage. Of course this causes GC thrashing so the program doesn't seem to terminate before hitting the swapfile.
There must be some bug causing some data to stay live according to the GC longer than it should.
(* from the Larceny benchmark suite;;; MAZEFUN -- Constructs a maze in a purely functional way,;;; written by Marc Feeley.;;; ported to SML by Kavon Farvardin*)datatype maze_elm
= Pt of int * int
| Empty
structure Benchmark = structval hd = List.hd
val tl = List.tl
val concat = List.concat
val length = List.length
val null = List.null
val foldr = List.foldr
funtup1 (x, _) = x
funtup2 (_, x) = x
(* operations on maze elms *)funfst e = (case e
of Pt (x, _) => x
| _ => raise Fail "not a point"(* end case *))
funsnd e = (case e
of Pt (_, x) => x
| _ => raise Fail "not a point"(* end case *))
funmazeElmEqual p = (case p
of (Pt (x, y), Pt (a, b)) => x = a andalso y = b
| (Empty, Empty) => true
| _ => false(* end case *))
funmazeElmToString p = (case p
of Pt _ => " _"
| Empty => " *"(* end case *))
funprintStringMat mat =
app (fn lst => (app print lst; print "\n")) mat
(***********)(* the args to f are flipped, i.e. acc is on the left in Scheme *)funfoldl f id xs = letfunlp (xs, acc) = (case xs
ofnil => acc
| x :: xs => lp(xs, f (acc, x))
(* end case *))
in
lp (xs, id)
endfunfor lo hi f = letfunlp lo =
if lo < hi
then f lo :: lp (lo + 1)
elsenilin
lp lo
endfunlistRead lst i =
if i = 0then hd lst
else listRead (tl lst) (i-1)
funlistWrite lst i new =
if i = 0then new :: tl lst
else hd lst :: listWrite (tl lst) (i-1) new
funlistRemovePos lst i =
if i = 0then tl lst
else hd lst :: listRemovePos (tl lst) (i-1)
funmember x = List.exists (fn y => mazeElmEqual (x, y))
funhasDuplicates lst = (case lst
ofnil => false
| x :: xs => member x xs orelse hasDuplicates xs
(* end case *))
funmakeMatrix n m init =
for 0 n (fn i =>
for 0 m (fn j =>
init i j
)
)
funmatrixRead mat i j = listRead (listRead mat i) j
funmatrixWrite mat i j new =
listWrite mat i (listWrite (listRead mat i) j new)
funmatrixSize mat = (length mat, length (hd mat))
funmatrixMap f mat = map (fn lst => map f lst) mat
funnextRandom cur =
((cur * 3581) + 12751) mod 131072funshuffle lst = letfunshuf lst rand =
if null lst
thennilelseletval newRand = nextRandom rand
val i = newRand mod (length lst)
in
listRead lst i
:: shuf (listRemovePos lst i) newRand
endin
shuf lst 0(* <- the seed *)endfunodd n = n mod 2 = 1funeven n = n mod 2 = 0funcaveToMaze cave = matrixMap mazeElmToString cave
funpierce pos cave = matrixWrite cave (fst pos) (snd pos) pos
funneighboringCavities pos cave = letval size = matrixSize cave
val n = tup1 size
val m = tup2 size
val i = fst pos
val j = snd pos
funnotEmpty (i, j) = (case matrixRead cave i j
of Empty => false
| _ => true(* end case *))
in
concat [
if i > 0andalso notEmpty (i-1, j)
then [Pt (i-1, j)]
elsenil,
if i < n-1andalso notEmpty (i+1, j)
then [Pt (i+1, j)]
elsenil,
if j > 0andalso notEmpty (i, j-1)
then [Pt (i, j-1)]
elsenil,
if j < m-1andalso notEmpty (i, j+1)
then [Pt (i, j+1)]
elsenil
]
endandchangeCavity cave pos newID = letfunchange cave pos newID oldID = letval i = fst pos
val j = snd pos
val cavityID = matrixRead cave i j
inif mazeElmEqual (cavityID, oldID)
then foldl (fn (c, nc) =>
change c nc newID oldID)
(matrixWrite cave i j newID)
(neighboringCavities pos cave)
else cave
endin
change cave pos newID (matrixRead cave (fst pos) (snd pos))
endandtryToPierce pos cave = letval ncs = neighboringCavities pos cave
inif hasDuplicates
(map (fn nc => matrixRead cave (fst nc) (snd nc)) ncs)
then cave
else pierce
pos
(foldl (fn (c, nc) => changeCavity c nc pos)
cave
ncs)
endandpierceRandomly possibleHoles cave = (case possibleHoles
ofnil => cave
| hole :: rest => pierceRandomly rest (tryToPierce hole cave)
(* end case *))
funmakeMaze n m = ifnot (odd n andalso odd m)
thenraise Fail "n and m must be odd"elseletfuninit i j = if even i andalso even j
then Pt (i, j)
else Empty
val cave = makeMatrix n m init
val possibleHoles = concat (
for 0 n (fn i => concat (
for 0 m (fn j =>
if even i andalso even j
thennilelse [Pt (i, j)]
))
))
in
caveToMaze (pierceRandomly (shuffle possibleHoles) cave)
endfungo (n, m) =
printStringMat (makeMaze n m)
endstructure Main =
structval iterations = 1val n = 11val m = 11funmain _ = letfundoit () = Benchmark.go (n, m)
funlp0 = ()
| lp n = (doit(); lp (n-1))
funstart () = lp iterations
in
start ()
endendval _ = Main.main (CommandLine.name (), CommandLine.arguments ())
The text was updated successfully, but these errors were encountered:
The following benchmark program (
seq-mazefun
) executes pretty quickly inMLton
, but after compiling with Manticore it has runaway memory usage. Of course this causes GC thrashing so the program doesn't seem to terminate before hitting the swapfile.There must be some bug causing some data to stay live according to the GC longer than it should.
The text was updated successfully, but these errors were encountered: