Mam dziwne spostrzeżenie na temat zlewów ze strumieniem scalaz. Pracują wolno. Czy ktoś wie, dlaczego tak się dzieje? Czy jest jakiś sposób na poprawę wydajności?Jak poprawić wydajność kodu za pomocą Sink?
tutaj są odpowiednie części mojego kodu: wersja bez zlewu
//p is parameter with type p: Process[Task, Pixel]
def printToImage(img: BufferedImage)(pixel: Pixel): Unit = {
img.setRGB(pixel.x, pixel.y, 1, 1, Array(pixel.rgb), 0, 0)
}
val image = getBlankImage(2000, 4000)
val result = p.runLog.run
result.foreach(printToImage(image))
ten trwa ~ 7s do wykonania
wersji z umywalką
//p is the same as before
def printToImage(img: BufferedImage)(pixel: Pixel): Unit = {
img.setRGB(pixel.x, pixel.y, 1, 1, Array(pixel.rgb), 0, 0)
}
//I've found that way of doing sink in some tutorial
def getImageSink(img: BufferedImage): Sink[Task, Pixel] = {
//I've tried here Task.delay and Task.now with the same results
def printToImageTask(img: BufferedImage)(pixel: Pixel): Task[Unit] = Task.delay {
printToImage(img)(pixel)
}
Process.constant(printToImageTask(img))
}
val image = getBlankImage(2000, 4000)
val result = p.to(getImageSink(image)).run.run
ten trwa 33 sekund, aby wykonać . Jestem całkowicie zdezorientowany z powodu tej znaczącej różnicy.
Dzięki, że wyjaśnia to dziwne zachowanie. Myślałem, że to raczej lekki proces. – user2963977