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:
File
>Import ...
>General
>Existing Projects into Workspace
- point Eclipse to the
image-example
directory, selectimage-example
and hitFinish
You should see the project in Eclipse:
Open 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 Pixel
by @miniboxed
:
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 map
in Image
:
but did not add the annotation to method map
in ImageImpl
, which extends Image
:
Let’s fix that:
If we recompile, the error is gone, but we get another batch of 26 warnings
:
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
Project
>Properties
(if that’s disabled, make sure theimage-example
project is selected) - in the window go to
Scala Compiler
and add-P:minibox:mark-all
to theAdditional command line parameters
field.
As explained in the command line options, the -P:minibox:mark-all
flag will mark all type parameters with @miniboxed
automatically.
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
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