[PATCH 0 of 3 V2] posixfile for Windows in pure Python

Dan Villiom Podlaski Christiansen danchr at gmail.com
Wed May 18 01:37:25 CDT 2011


On 18 May 2011, at 01:11, Adrian Buehlmann wrote:

> Looks like Mercurial on PyPy isn't yet *that* much fun then.
>
> I'm wondering if they have a framework/API for writing modules in C.
>
> This one sounds interesting:
> http://morepypy.blogspot.com/2010/04/using-cpython-extension-modules-with.html

PyPy provides two extension APIs: cpyext and ctypes. cpyext is a  
compatibility layer for the CPython API. Ironically however, their  
performance characteristics in PyPy are the opposite of what they are  
in CPython. cpyext is fairly slow, due to bridging between the  
internal representations in PyPy and what the CPython API expects.  
ctypes should be faster, and there's work ongoing which would allow  
the JIT to compile it into direct function calls.

A brief benchmarking:

PyPy, pure:         17.041s
CPython, pure:      10.385s
PyPy, optimized:    15.805s
CPython, optimized: 6.280s

(I did a single run of ‘hg verify’ on the Mercurial repository itself  
on Linux, and took the user-space time to eliminate noise.)

So, in other words: if we want to use the optimized C implementation  
on PyPy, our best bet is probably to use ctypes. The performance of  
PyPy & cpyext is unlikely to ever rival CPython. Tuning the pure  
modules would be nice, of course, but I don't know how much there is  
to gain.

--

Dan Villiom Podlaski Christiansen
danchr at gmail.com



More information about the Mercurial-devel mailing list