Image Processing Example - PNWScala
The following example is based on the miniboxing presentation at PNWScala. A huge thanks to Thomas Lockney and the PNWScala organizers for the wonderful conference and the confreaks guys who recorded the presentation!
This page will guide you through the steps necessary to run the example in the presentation. The pureimage library is located at github.com/stephenjudkins/pureimage. The mock-up used for the presentation is located at github.com/VladUreche/image-example.
To start, clone the pureimage mock-up:
Let’s generate the Eclipse project files to load the project in the IDE:
Cool. Now, all you need is the latest Scala IDE for Eclipse to load the project. Please use a version for Scala 2.11, in order to stay compatible with the rest of the project. Now, to load the project:
Existing Projects into Workspace
- point Eclipse to the
You should see the project in Eclipse:
Test.scala from package
image.example, located in
src/main/scala, and run it:
On my laptop, I got the following times:
The miniboxing plugin generated a couple of warnings during compilation:
One such warning is:
So let’s go in and fix that. Open
Pixel.scala and mark the type parameter
Repr of class
We can fix the other 8 warnings that appear and recompile. Surprisingly, after compiling again, we get an error:
This is because we added the
@miniboxed annotation to method
but did not add the annotation to method
ImageImpl, which extends
Let’s fix that:
If we recompile, the error is gone, but we get another batch of
Let’s try to run the program now, despite the warnings:
So by adding a couple of annotations, we just shaved off one quarter of the running time:
Maybe this miniboxing thing is actually worth it…
Let’s now address all the warnings. But let’s be smart about it:
- go to
Properties(if that’s disabled, make sure the
image-exampleproject is selected)
- in the window go to
Scala Compilerand add
Additional command line parametersfield.
As explained in the command line options, the
-P:minibox:mark-all flag will mark all type parameters with
Recompile and you should not see any more warnings. Now let’s run again:
Wow, that’s four times faster than our initial running time. That’s what miniboxing can do for numeric-intensive applications!
Comments are always welcome! But to make the best use of them, please consider this:
- If you have questions or feedback regarding the content of this page, please leave us a comment!
- If you have general questions about the miniboxing plugin, please ask on the mailing List.
- If you found a bug, please let us know on the github issue tracker.
Thanks! Looking forward to your messages!
comments powered by Disqus