Sieve of Eratosthenes performance; Scala very slow compared to Node.js
Lists vs. Arrays

The Scala version of your code ran surprisingly slower because you used a ListBuffer. In Scala you can think of a List as a traditional linked-list. Lists don't provide random access to their contents. That is, accessing an object at index n requires O(n) time. This really slowed down your code because you index into A in both your inner and outer for-loop. 

To fix this problem you can simply use a different data structure like an Array.

object Sieve extends App {
  val n = 100000
  val a = Array.fill(n + 1)(true)
  a(0)  = false
  a(1)  = false
  val k = scala.math.sqrt(n).toInt

  for (i &lt;- 2 to k; if a(i)) 
    for (j &lt;- i * i to n by i)
      a(j) = false

  val res = a.zipWithIndex.filter(_._1).map(_._2)
  assert(res.length == 9,592)
}


Other Notes


_._1 represents accessing the first element in a tuple 
Tuples are one indexed
So if we have a tuple t we can access the 5th element with t._5
The first underscore is what is known as placeholder syntax. For example:




    val a = List.range(0, 9)
    val b = a.map(i =&gt; i + 1) 
    val c = a.map(_ + 1)       // placeholder syntax 



In the above code snippet b and c are equivalent
When we are using a map operation on a List of tuples we can combine the tuple element access operator (t._N) and placeholder syntax. As a result we get code that looks something like:




    val res = a.zipWithIndex.filter(_._1).map(_._2)