TL;DR: NodeBox-OpenGL gives you the sugar and power of Python and the ease of Processing, but with a significant speed penalty. The good news is: there’s lots of low-hanging fruit. Let’s submit some diffs!
Lynn Cherny’s talk, Data Visualization with NodeBox (Slides, Video) made an excellent case for using NodeBox as a framework for creative data visualization instead of Processing. NodeBox lets you code in Python instead of Java. And although NodeBox lacks Processing’s vibrant community of developers and rich ecosystem (including geomerative and toxiclibs), NodeBox comes with a lot built-in (flocking, particle systems, graphs), plus easy access to all the goodies you could ever want in Python.
So, I decided to give it a whirl and installed NodeBox-OpenGL (hereafter referred to as “NodeBox”). If you have mercurial, git, and pip installed, it’s not too bad (on OSX, you need to install pyglet from HEAD because version 1.2, which switches from using Carbon to Quartz, has not yet been released):
pip install hg+https://pyglet.googlecode.com/hg/ pip install git+https://github.com/nodebox/nodebox-opengl
Once that was out of the way, I decided the most instructive thing to do was to port an existing Processing sketch to NodeBox. BoxyLady2, a 72-line sketch by analogpixel became 20 lines shorter (yay!), but also 11x slower (.375 fps for NodeBox, 4.4 fps for Processing v2.0b9). That’s a hell of a performance price to pay.
My rendered output is here (I used ImageMagick to stitch the frames together – it’s a ~9 MB animated gif)
Despite its performance problems, NodeBox does have a primitive that Processing is lacking: the
star. Interestingly, it was implemented using an inefficient intermediate class (
BezierPath) instead of directly in OpenGL, like the other primitives. Rewriting star in OpenGL (along with some cute tricks), I was able to commit
fast_star, a function that runs 23x faster. So, of course, I made this.
And, as advertised earlier, Python’s many great libraries are easily callable from NodeBox. I decided to make a quick project,
fast_star and scikit-image. It barely scratches the surface of what can be done, but it’s a fun demo.
So why is NodeBox so much slower? I took a look at
context.py, the file where all the drawing happens. I was able to increase the performance of all the drawing primitives (
numpy, I was able to get 2.7 fps — about half as fast as processing.js, and over 4x as fast as my existing Python implementation (Apple-supplied Python 2.7.1). So if you’ve got frame rate problems in NodeBox, PyPy may very well be your answer.
Even with the JIT, and some OpenGL improvements, NodeBox lags behind both Processing implementations. Perhaps they employ occlusion culling or other tricks to avoid doing unnecessary work. If you’re a committer on Processing.org, please take a look at NodeBox and tell us what we could be doing better.
(latest + PyPy)
(no image saving)
Long story short, NodeBox has a lot to like, but has a long way to go before it can compete with Processing in terms of community and performance. But that means making incremental improvements is really easy. Go pull out your profiler —@huyng wrote a great post on profiling Python — and submit a pull request!
Originally published: Sat, 06 Jul 2013 to https://runningwithdata.tumblr.com/post/54781756667