scalaz stream - How to improve performance of code with Sink? -
i have weird observation scalaz-streams sinks. working slow. know why that? , there way improve performance?
here relevant parts of code: version without sink
//p parameter 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))
this takes ~7s execute
version sink
//p same before def printtoimage(img: bufferedimage)(pixel: pixel): unit = { img.setrgb(pixel.x, pixel.y, 1, 1, array(pixel.rgb), 0, 0) } //i've found way of doing sink in tutorial def getimagesink(img: bufferedimage): sink[task, pixel] = { //i've tried here task.delay , task.now 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
this 1 takes 33 seconds execute. totally confused here because of important difference.
in sec case allocating task each pixel, , instead of straight calling printtoimage through task, , it's much more steps in call-chain.
we utilize scalaz-stream lot, believe it's overkill utilize type problems. code running within process/channel/sink should much more complicated simple variable assignment/update.
we utilize sinks write info stream databases (cassandra) , utilize batching, it's high overhead write individual rows. process/sinks super convenient abstraction, more high level workflows. when it's easy write for-loop suggest write for-loop.
scalaz-stream
No comments:
Post a Comment