While I’ve been having a ton of fun with my MakerBot Thing-O-Matic, generating the gcode to run the machine takes an amazingly long. Despite having a quad-core Core2Duo running a hair over 2.5GHz, Skeinforge is not efficient. Python isn’t fast at that much number crunching, and the process that turns the 3D model into a series of 2D layers is almost totally serial.
I’ve been using a program called Pleasent3D to look at the gcode Skeinforge makes to look for errors. While reading about the software, I found a blog entry by the author describing how he got tired of waiting on Skeinforge and then ported the gcode gene ration algorithms to Objective-C and ended up with a massive speedup (up to 230x in one module).
Now I don’t want to get away from the official MakerBot way of doing things yet, I’m not that confident. The easiest way to speed up Skeinforge would be to speed up Python. People used to recommend Psycho, but it is no longer updated and doesn’t run in 64-bit mode (like Python does on my Mac). I finally got around to playing with PyPy, which grew out of Psyscho, to see just how much of a difference it made. I’d seen references to other people doing this, so I knew all the libraries had to be there.
Installing PyPy & TkInter
Installing PyPy was as easy as downloading a pre-built binary distribution and unzipping it. The problem is that to use PyPy with Skeinforge (and therefor ReplicatorG), you need to have TkInter installed. I found a great set of steps to follow in a PyPy blog entry about using the IDLE IDE. The only problem was the TkInter package for PyPy is looking for Tk8.4, but OS X Lion has 8.5. Luckily since it’s a point release I figured I could just swap them out and it worked out fine. I updated the files in the tkinter-pypy install file and it worked fine (updated zip for download). Making ReplicatorG use PyPy is as easy as selecting it in the preferences window.
Benchmarking
So I ran some benchmarks by running a couple of models through with both CPython and PyPy with my normal profile, no support:
Model | CPython | PyPy | Speed |
---|---|---|---|
20mm calibration cube | 19s | 13s | 1.46x |
Vica illusion sculpture | 5m 36s | 1m 48s | 3.11x |
V8 cam shafts | 6m 37s | 1m 18s | 5.09x |
Tank! | 2h 45m 29s | 38m 45s | 4.27x |
As you can see, PyPy can be dramatically faster. I chose the Tank! model (which unmodified is about 4x the max print area on my ToM) to see just how big the difference would be on very complex models. Getting a 4x speedup is a great result, but there is just one minor problem: the gcode is different. Generating gcode should be deterministic. Given the same profile, the same model, and the same version of Skeinforge you should always get the same output.
In the case of the 20mm calibration cube, the gcode is identical. But for every other model, it’s different. The F parameters on the move commands are different, and sometimes the points seem different. I haven’t looked at it too hard yet. It seems like it might be due to floating point differences, but PyPy is supposed to be a drop in replacement for most Python programs so I doubt this should be happening.
I’m going to have to look into it further.
Sounds cool. I know that PyPy doesn’t guarantee that dictionaries will be iterated in the same (arbitrary) order as CPython, could it be that?
You’re right, and that did explain one of the two kinds of changes that I saw in the generated GCode. The other seems to be due to the higher precision floating point operations PyPy uses. Both are mentioned (with a note from a PyPy developer) in the follow-up post.
Mmmmm PyPy. I just wish it was easier to get TkInter working on Windoze. Ez_setup doesn’t work unfortunately.
Have you tried printing the new pypy’d versions yet? I’m curious to see a side-by-side if they are usable or not.
Since a few days after I did the full comparison I’ve been using PyPy exclusively. As I type this, I’m about 2 hours into a 3 hour print (part of that great differential that’s been featured on Thingiverse). There is no external difference, since it’s only tiny changes in the internal support structure. It’s been working great, and the speed is much nicer.
Thanks for the updated tkinter. Slicing fast in RepG now!
Here are step-by-step instructions for getting PyPy working in OSX:
https://groups.google.com/forum/?hl=en&fromgroups=#!topic/makerbot/lv9AupRqSnY