New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scala 2.13.2 Vector prepending performance regression #12027
Comments
Note that this does not get any better using explicit
|
I'm taking a look to understand why this used to perform okay. But you'll get better performance in both cases with something like:
Internally, that will create a single |
The // appendAll (suboptimal but avoids worst performance gotchas)
override def appendedAll[B >: A](suffix: collection.IterableOnce[B]): Vector[B] = {
import Vector.{Log2ConcatFaster, TinyAppendFaster}
if (suffix.iterator.isEmpty) this
else {
suffix match {
case suffix: collection.Iterable[B] =>
suffix.size match {
// Often it's better to append small numbers of elements (or prepend if RHS is a vector)
case n if n <= TinyAppendFaster || n < (this.size >>> Log2ConcatFaster) =>
var v: Vector[B] = this
for (x <- suffix) v = v :+ x
v
case n if this.size < (n >>> Log2ConcatFaster) && suffix.isInstanceOf[Vector[_]] =>
var v = suffix.asInstanceOf[Vector[B]]
val ri = this.reverseIterator
while (ri.hasNext) v = ri.next() +: v
v
case _ => super.appendedAll(suffix)
}
case _ => super.appendedAll(suffix)
}
}
}
|
Right, |
Thanks, @szeiger. I'll add the |
@oxbowlakes great catch! kudos for isolating & reporting |
Also thanks for the circumspect locution, "mature application", in lieu of, "old code". |
I have a mature application currently running scala 2.13.1 and performing its daily task comfortably with
-Xmx4g
and taking about 30-60s. If I make the change to compile/run using 2.13.2 (with no other changes) and run, it goes out of memory (even when increased to-Xmx16g
) after about 5 minutes of running. If I capture a stack trace when running (and when it throws anOutOfMemoryError
), it looks like this:This is a single Vector being built up by repeatedly prepending Vectors which would typically be of size 1 and occasionally of size 2. There would be around 250_000 such vectors.
Here is the reproduction.
Scala 2.13.1
Scala 2.13.2
The text was updated successfully, but these errors were encountered: