By: Simon Danisch
Responsive and fun interactivity is notoriously hard! But it’s also the key to less frustration and more patience when working on a project.
There are endless important projects that humanity needs to solve. To become less of a burden to the environment and have a better society we constantly need to advance the state of the art.
Still, people give up on doing this when the initial amount of patience, motivation and curiosity is depleted without getting new incentives.
This actually happened to me with my 3D modeling hobby a few years ago. Not only was the 3D software difficult to learn, it also turned unresponsive fairly quickly, even on a powerful machine.
Just as an example, rendering a 30 second clip in high quality took ~2 weeks with my PC running day and night. This slowness drained my patience and at some point I decided that this is too much hassle for a hobby.
Half a year later, I ran into a similar problem when working on a computer vision pipeline. We simply couldn’t find frameworks which were fast enough for real time processing while maintaining high programming productivity. This time I didn’t give up, but the job could have been much more fun and productive!
At this point I decided that I want to work on software that turns really tough problems like object recognition of 3D models into weekend projects.
I started working on GLVisualize, a library for fast and interactive graphics written in Julia.
Visualizing something is the first step to understanding and it allows us to explore huge problem spaces that were invisible before.
But current tools seem to be divided into 2D and 3D libraries, high performance libraries, which are kind of a hassle to use, and easily usable libraries which turn into an unresponsive mess quickly.
So with my background, this seemed like a worthy start!
While there are several reasons for choosing Julia, today I want to show you its impressive speed despite being an easy-to-use dynamic language.
Let me show you the benefit with two toy examples (all graphics including the plots were produced with GLVisualize!).
It takes a point t0 and parameters a to d and returns a new point. Could you imagine what kind of line this will draw, when recursively applying it to the new result and changing parameters?
I guess no one has such a powerful brain, which is why we visualize these kind of things, together with sliders to explore the function:
These are 100,000 points, and as you can see GLVisualize can deal with that amount easily.
Lets see how long we could have stayed at pleasant interactive speeds in another language.
Lets take for example Python, a language comparable in usability:
|max seconds Julia||0.193422334|
|max seconds Python||13.630093812942505|
As you can see, computation times jump beyond one second at around 10⁵ points for Python, while Julia stays interactive with up to 10⁷ points.
So if you’re interested in a higher resolution in Python you better crank up your patience or call out to C, eliminating all convenience of Python abruptly!
Next example is a 3D mandelbulb visualization:
One step through the function takes around 24 seconds with Julia on the CPU, which makes it fairly painful to explore the parameters.
So why is the shown animation still smooth? Well, when choosing Julia, I’ve been betting on the fact that it should be fairly simple
to run Julia code on the GPU. This bet is now starting to become reality.
Here are the benchmark results:
|max seconds cpu||24.275534426|
|max seconds cuda||0.128474155|
This means that by running Julia on the GPU we can still enjoy a smooth interaction with this function.
But the problem is actually so hard, that I can’t run this interactively at the resolution I would like to.
As you can see, the iso surface visualization still looks very coarse. So even when using state of the art software, you still run into problems that won’t compute under one second.
But with Julia you can at least squeeze out the last bit of performance of your hardware, be it CPU or GPU, while enjoying the comfort of a dynamic high level language!
I’m sure that with Julia and advances in hardware, algorithms and optimizations, we can soon crack even the hardest problem with ease!
CPU: Intel® Core™ i7-6700 CPU @ 3.40GHz × 8
GPU: GeForce GTX 950