I've been writing accelerator modules for PyOpenGL for the last two days. I think I've got to a reasonably comfortable point. I've got a Numpy FormatHandler and an ArrayDatatype written. With some judicious use of cdef'd typed self variables there's a lot of overhead eliminated from the wrapper operation. To make it really fast, however, I'd have to make almost the entirety of the wrapping code Cython and would have to link into ctypes at quite a few points... at which point I could have just generated a Cython wrapper.
Cython is pleasant work work with, I've settled into a pattern of dumping Python code in, running the compiler, running a test suite to be sure everything's working, then looking at the generated code to optimize the hot-spots with typed references and the like.
I still haven't figured out how to make the type-dispatching code algorithmically faster. I've eliminated most of the Pythonic overhead, but it's still doing a getattr for the __class__ reference and then a dictionary lookup for the handler.
Pingbacks are closed.