[Python-Dev] Register-based VM for CPython

Kristján Valur Jónsson kristjan at ccpgames.com
Sun Nov 18 12:18:45 CET 2012


Interesting work indeed.
From profiling CPython it has long been clear to me that enormous gains can be made by making instruction dispatching faster.  A huge amount of time is spent in the evaluation loop.  I have also been making small inroads to offline bytecode optimization.  Identifying common patterns and introducing special opcodes to deal with them.  Obviously using register addressing makes such an approach more effective.

(Working with code objects is fun and exciting, btw, and the reason for my patch http://bugs.python.org/issue16475)

K

From: Python-Dev [mailto:python-dev-bounces+kristjan=ccpgames.com at python.org] On Behalf Of Victor Stinner
Sent: 17. nóvember 2012 01:13
To: Python Dev
Subject: [Python-Dev] Register-based VM for CPython


The WPython project is similar to my work (except that it does not use registers). It tries also to reduce the overhead of instruction dispatch by using more complex instructions.
http://code.google.com/p/wpython/

Using registers instead of a stack allow to implement more optimizations (than WPython). For example, it's possible to load constants outside loops and merge "duplicate constant loads".

I also implemented more aggressive and experimental optimizations (disabled by default) which may break applications: move loads of attributes and globals outside of loops, and replace binary operations with inplace operations. For example, "x=[]; for ...: x.append(...)" is optimized to something like "x=[]; x_append=x.append; for ...: x_append(...)", and "x = x + 1" is replaced with "x += 1".

Victor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20121118/04c05c17/attachment.html>


More information about the Python-Dev mailing list