Re: inline function call



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
inline.

HOWEVER, there is a slick product called Psyco:

http://psyco.sourceforge.net/

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@xxxxxxxx>
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.

.



Relevant Pages

  • Re: Python 3K or Python 2.9?
    ... function/method argument that might as well be hidden in the compiler ... You could add some syntax to Python such that '.x' was equivalent to ... def factory: ... C.method = foo ...
    (comp.lang.python)
  • Re: calloc.... Why?
    ... >> And using references doesn't make the optimizer's job any ... >and registers), but when the function's inline, the stack ... The compiler can choose to inline ... int foo = 10; ...
    (comp.lang.cpp)
  • Re: inline function call
    ... > 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 ...
    (comp.lang.python)
  • Re: Official definition of call-by-value (Re: Finding the instance reference...)
    ... Yes, which is why we have int, str, and list classes which, unlike some ... Since pickle can't predict what aspects of the ... you can't do so in Python. ... with a foo attribute. ...
    (comp.lang.python)
  • Re: Some "pythonic" suggestions for Python
    ... aspects of the S language. ... Currently in Python ... assigns the name foo to a function object. ... Note that my code would actually return a list of lists ...
    (comp.lang.python)