2014-07-07

Waking up at 6:30 AM has bestowed upon me a blissful, irritant-free period that is perfect for contemplation, so of course I used it for a few experiments instead.

With all the hoopla around Go concurrency, a surprisingly large number of folk have been pursuing similar avenues for writing nice, clean concurrent code, and analogues have sprung up all over the place — like Clojure‘s core.async, for instance, which is around a year old and which I’m quite fond of.

In Python land, one of the available options is Rob Galanakis’ goless, which I’ve been tracking fairly closely. It provides Go-like primitives and works wonderfully out-of-the-box with PyPy, providing in-process coroutines with pretty much zero hassle.

As it happens, PyPy is now my default Python interpreter1, so goless is a very nice addition to my toolkit, all the more so now that I’m starting to benchmark and profile most of my code as a matter of course — partly to figure out where the bottlenecks are, and partly to figure out ways to make it go faster2.

And it’s been quite entertaining, really — I’ve found a few interesting things here and there, and profile results from even trivial bits of code is quite informative.

For instance, here’s one of the goless examples (the very first one I picked up, really), rewritten in Hy (and with inline profiling until #618 is addressed):

…and here’s the profile result (in SVG format), courtesy of gprof2dot:



Next up, applying this to a number of things I’m building around an MQTT broker…

Since 2.2.x, and for most things that don’t require numpy, that is. Ironically, I’m falling back to the system Python via pyenv to do most of my number-crunching for the moment. ↩

Which brings to mind that I need to get to grips with profiling in Go as well. It’s not magical, you know. ↩




"Go-like concurrency (and profiling!) in Hy and PyPy" was written by Rui Carmo for The Tao of Mac and was originally posted on Monday, Jul 7th 2014. Except as noted, it's ©2014 Rui Carmo and licensed for reuse under CC BY-NC-ND 3.0.

As usual, please consider donating towards hosting and bandwidth costs.

Show more