RE: [Python-Dev] Re: The Other Py2.4 issue?
by Delaney, Timothy C (Timothy)
Adam Bark wrote:
> Now this might sound a bit stupid but I've only been programming in
> python for about 6 months and before that about the same on VB. Anyway
> here goes, as python is built in C & C++ surely every piece of python
> code has a corresponding piece of C/C++ albeit more complex. So would
> it be possible to somehow make a program to convert the Python to C &
> C++ which can then be compiled with a C/C++ compiler.
Yes. And it would run at about the same speed as CPython.
The only way to significantly improve this is to remove much of the
dynamism of Python. As an example, I've been playing around with
Raymond's constant binding - making it do more aggressive binding (I'll
give an example later). By binding constants, I'm able to reduce the
runtimes for psyco-compiled versions of friendly code (lots of things
that can be converted into constant references) from around 2 seconds to
less than 0.001 seconds.
That's a very significant speedup. Unfortunately, it doesn't translate
as well into real-world code - or even benchmarks (parrotbench for
example gets a slight speedup but it's not overly significant).
As a quick example if the changes I'm playing with,
0 JUMP_ABSOLUTE 15
15 LOAD_CONST (<unbound method Struct.__init__)
I've also been doing some peephole optimisations - the above actually
ends up being an immediate jump to the return bytecode, but that's
fairly useless. Using JUMP_ABSOLUTE instead of JUMP_FORWARD simplifies
Once I've got the code into a fit state I'll send it to you if you're
interested Raymond ...