Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does this crash the compiler?

Tags:

scala

sbt

I have this code:

var nodeMap:Map[Int, List[Node]] = Map[Int, List[Node]]()

nodeMap = Map[Int, List[Node]]() ++ nodes.par.groupBy( x => x.getClosest(centers))

x.getClosest returns an Int. When I go to compile this, the compiler crashes saying it's out of memory. However, when I do this:

var nodeMap:Map[Int, List[Node]] = Map[Int, List[Node]]()

nodeMap = nodes.groupBy( x => x.getClosest(centers))

It works fine.

Why?

like image 486
dave Avatar asked Dec 07 '25 07:12

dave


1 Answers

The Scala compiler has some issues with complex expressions; if you ran out of memory proper (i.e. OutOfMemoryException) it's likely a bug, however it is more often the case that the compiler runs out of stack space, in which case you can add the flag -Xss=256m (where the number is obviously up to you) to work around the problem. This is particularly common with complex expressions (string and list concatenations, for example).

like image 110
Tomer Gabel Avatar answered Dec 10 '25 00:12

Tomer Gabel