Bytecode optimisation

M.-A. Lemburg mal at lemburg.com
Tue May 18 04:02:05 EDT 1999


[Byte code optimizer]

In case you do consider a rewrite, you might try to convert the
peep hole optimizer written by Skip Montanaro to make use
of the bytecodehacks package:

	http://www.automatrix.com/~skip/python/

It uses a block oriented pipe design which makes it very easy
to add new optimizations or shuffle the various opts around.
He has also written a nice resume of his findings using this
optimizer which he presented at the last Python conference.

About adding type information to variables:

Wouldn't it be possible to make the optimizer recognize
the following type of assert statement and then use the
implicit information contained in it...

assert type(x) is types.IntegerType
x = x + 2

There are many advantages to this construct, since it can
be used to debug *and* optimize code. It also is perfectly
valid Python and shows the programmers intent pretty well,
IMHO.

BTW, the same could be done to mark and check constant variables:

markconstant(x)
...
assert isconstant(x)

with markconstant() and isconstant() being some dynamic
implementation to mark objects with certain information
(using e.g. weak reference dictionaries). The optimizer could
then recognize the assert statements and use the included
information to e.g. preload globals. Non-optimized code
would perform the check for means of debugging.

-- 
Marc-Andre Lemburg
______________________________________________________________________
Y2000:                                            Y2000: 227 days left
Business:                                      http://www.lemburg.com/
Python Pages:                 http://starship.python.net/crew/lemburg/






More information about the Python-list mailing list