Hello , I am new to ZIO .
When i was trying to solves @jdegoes "zio-intro-game" exercises , i encountered a StackOverflowError when playing with Chunk in CatIncremental
In my implementation i was folding/concatenating multiple chunks and StackOverflowError occurred when traversing the resulting chunk .
i made the example below to illustrate the problem
object TestChunk extends App {
val chunkOk = Chunk.fromIterable(1 to 10000)
println(chunkOk.fold(0)(_ + _)) // OK
val chunkKo = (1 to 10000).foldLeft(Chunk[Int]())(_ ++ Chunk.single(_))
println(chunkKo.fold(0)(_ + _)) // KO StackOverflowError
}
The stack trace error
Exception in thread "main" java.lang.StackOverflowError
at zio.Chunk$Concat.apply(Chunk.scala:873)
at zio.Chunk$Concat.apply(Chunk.scala:873)
at zio.Chunk$Concat.apply(Chunk.scala:873)
...
i will try to figure out a fix.
It works for me on the latest master 馃
Sorry but i still have the same error on the master .
i am using adoptopenjdk ( i tried version 8 and 11 ) with default stack settings( -Xss 1024)
PS : the problem is due to Chunk$Concat.apply witch is not tail recursive .
@arism @regiskuckaertz Yes, Chunk's Concat is not stack safe under repeated concatenations currently. It can be made safe by using an explicit stack when traversing the chunk, at the expense of lots of performance probably.
We should document this.
Resolved by #3754.
Most helpful comment
@arism @regiskuckaertz Yes, Chunk's Concat is not stack safe under repeated concatenations currently. It can be made safe by using an explicit stack when traversing the chunk, at the expense of lots of performance probably.
We should document this.