inline function call

Stuart D. Gathman stuart at
Wed Jan 4 16:57:56 CET 2006

On Wed, 04 Jan 2006 13:18:32 +0100, Riko Wichmann wrote:

> I'm googeling since some time, but can't find an answer - maybe because 
> the answer is 'No!'.
> Can I call a function in python inline, so that the python byte compiler 
> does actually call the function, but sort of inserts it where the inline 
> call is made? Therefore avoiding the function all overhead.

In standard python, the answer is no.  The reason is that all python
functions are effectively "virtual", and you don't know *which* version to

HOWEVER, there is a slick product called Psyco:

which gets around this by creating multiple versions of functions which
contain inlined (or compiled) code.  For instance, if foo(a,b) is often
called with a and b of int type, then a special version of foo is compiled
that is equivalent performance wise to foo(int a,int b).  Dynamically
finding the correct version of foo at runtime is no slower than normal
dynamic calls, so the result is a very fast foo function.  The only
tradeoff is that every specialized version of foo eats memory.  Psyco
provides controls allowing you to specialize only those functions that
need it after profiling your application.

	      Stuart D. Gathman <stuart at>
Business Management Systems Inc.  Phone: 703 591-0911 Fax: 703 591-6154
"Confutatis maledictis, flamis acribus addictis" - background song for
a Microsoft sponsored "Where do you want to go from here?" commercial.

More information about the Python-list mailing list