Scala array performance operations (scalacl plugin)

Are there any drawbacks to using the plugin plugin ?

I plan to use scala in my project. I wrote some code in scala to see its runtime.

(1 to 1000000).map(1 + _).sum 

1. Without a plugin

compiled something like this:

 BoxesRunTime.unboxToInt(((TraversableOnce)Predef..MODULE$.intWrapper(1).to(1000000).map(new MyScala..anonfun.1(), IndexedSeq..MODULE$.canBuildFrom())).sum(Numeric.IntIsIntegral..MODULE$)); 

and run for about 375 ms

2. With plagiarism plugin

  int i = 1; int j = 1000000; int k = j; int m = i; for (VectorBuilder localVectorBuilder = new VectorBuilder(); m <= k;) { int n = m; localVectorBuilder.$plus$eq(BoxesRunTime.boxToInteger(1 + n)); m += 1; } int a = BoxesRunTime.unboxToInt(localVectorBuilder.result().sum(Numeric.IntIsIntegral..MODULE$)); 

259 ms

+7
source share
1 answer

Possible cons that I can think of:

1) The loop optimization seems to work, and the developer seems very competent, but he says in bold on the screen "About ScalaCL" " ScalaCL is not ready for production! ". In other words, there is little chance that you can introduce errors and instability.

2) You must remember that each time you compile with the plugin, otherwise you may suddenly find that you have performance problems. You cannot be sure that the plugin will be supported / compatible in the medium or long term.

3). You can rely on your optimizations, which will lead to writing inefficient code, while identifying and optimizing manually bottlenecks can lead to faster code in general. In other words, it can essentially be β€œpaper over cracks”

4) This is an additional library dependency and adds complexity to your build files

You asked for the cons, but they are pretty minor compared to its advantages. Personally, I would not hesitate to discuss the optimization of the cycle for personal projects; not so sure about cl collections (I tried them and found that my GPU is a bit slower than my processor - obv depends on the available hardware), but I think the project has a great future, regardless of the standard compiler and libraries . I saw very sharp accelerations (about 20 times faster) for some code.

+10
source

All Articles