A PYTHON PREPROCESSOR

Michael Hudson mwh21 at cam.ac.uk
Thu May 18 15:20:16 EDT 2000


Glyph Lefkowitz <glyph at twistedmatrix.com> writes:

> Guido van Rossum <guido at python.org> writes:
> 
> > Glyph Lefkowitz wrote:
> > 
> > > Inlining of methods!
> > > 
> > > Since python variable name / method lookup is so expensive, I believe
> > > this would be a significant speedup.  Comments?
> > 
> > But this would require compile time type analysis.
> > Typically, when you see code of the form ``obj.method(arg)'',
> > *you* (the programmer) have a good idea of what the class of
> > obj would be at run-time -- but the poor Python parser does
> > not share this knowledge.
> 
> Hmm.  It would be possible to do inlining of functions, though, right?
> I suppose this isn't quite the same thing as inlining methods, but it
> would still be helpful. (and with the extra "self" argument, you can
> make it *behave* like inlined methods)
> 

Bytecodehacks can do this too (it slices! it dices!):

http://bytecodehacks.sourceforge.net/

specifically:

http://bytecodehacks.sourceforge.net/bch-docs/bch/module-bytecodehacks.inline.html

This module is broken in the April2000 release, so get it from CVS or
apply this patch to bytecodehacks.inline:

Index: inline.py
===================================================================
RCS file: /cvsroot/bytecodehacks/bytecodehacks/bytecodehacks/inline.py,v
retrieving revision 1.2
diff -u -r1.2 inline.py
--- inline.py   2000/03/15 20:55:42     1.2
+++ inline.py   2000/05/18 19:10:28
@@ -38,7 +38,6 @@
             code.co_consts=code.co_consts+list(fcode.co_consts)
             code.co_varnames=code.co_varnames+list(fcode.co_varnames)
             code.co_names=code.co_names+list(fcode.co_names)
-            code.co_stacksize=code.co_stacksize+fcode.co_stacksize
 
     return func.make_function()

FWIW, inlining does seem to result in a fair speed up (20%?) in some
cases (but all of these might well be cheesy rigged examples).

Cheers,
M.

-- 
93. When someone says "I want a programming language in which I
    need only say what I wish done," give him a lollipop.
     -- Alan Perlis, http://www.cs.yale.edu/~perlis-alan/quotes.html



More information about the Python-list mailing list