PyPy3 + Blender

So PyPy3 2.1 beta1 was released a few weeks ago. It would be interesting to see how it plays with Blender. Unfortunately, no 64-bit version yet.

For those who don’t know, PyPy contains a JIT-compiler which should make Python faster (not necessarily in ALL cases):

PyPy is a very compliant Python interpreter, almost a drop-in replacement for
CPython 2.7.3 or 3.2.3. It’s fast due to its integrated tracing JIT compiler.

This is very exciting, but very long term. Blender won’t work at all with PyPy as long as CPyExt is still in alpha, and even then the Python/C boundary would get a considerable performance hit. The long term solution would be beyond the skill of mortals (in other words, we have to ask Ideasman), to port all Python/C calls to cffi.
I haven’t played with this myself though, so what I say could be wrong or outdated.

I saw somewhere in an old thread, Ideasman was interested in PyPy. Maybe we could give him a heads up…Or wait until the final release.

Note that the JIT has a very high warm-up cost, meaning that the programs are slow at the beginning. If you want to compare the timings with CPython, even relatively simple programs need to run at least one second, preferrably at least a few seconds. Large, complicated programs need even more time to warm-up the JIT.

PyPy has a GIL.

http://doc.pypy.org/en/latest/faq.html

Could be interesting for complex scripts, which compute a lot. But for everything else? I really don’t know. If there was no GIL, that would give a huge performance boost on multicore systems, but as long as there is, I can live with CPython.

The PyPy people have a separate GIL-less branch that is still in development, it is called STM. I suspect it will be ready by the time Blender could use it.

This seems like a very cool project, it’s bad that the Python community has not looked into JIT code in a good mood. I do not know why, perhaps it was still experimental to go mainstream.

The benefits are enormous, here’s a simple script I have written to test it.

System details:
Windows 8 64 bit, Intel i5 2320, 4GB RAM

Program details:

  • PyPy 32 bit
  • Blender 2.68 - Python 3.3.0 MSC 1500 32 bit

# Minified version of http://code.google.com/p/benchrun/


import sys


if sys.platform == 'win32':
	from time import clock
else:
	from time import time as clock
	
def fib1(n):
	if n < 2:
		return n
	return fib1(n-1) + fib1(n-2)
	
if __name__ == '__main__':
	iterations = 40
	print('Fibonacci Benchmark')
	t1 = clock()
	fib1(iterations)
	t2 = clock()
	t3 = t2 - t1
	print('{0} iterations took {1:.5f} seconds'.
	format(iterations, t3))

Results:


PyPy Version
40 iterations took 25.73911 seconds


Blender Version
40 iterations took 65.86913 seconds

Blender fortunately waited silently to finish the opearation and did not crash. It could not stand the heat, hahaha! :smiley:

If PyPy is stable and approved by majority of developers, would you be interested for versions of Blender that are JITed?