Why is function call - recursive especially - in python so slow?

Terry Reedy tjreedy at udel.edu
Mon Oct 18 21:05:00 EDT 2004


<iviskic at uci.edu> wrote in message
> I'm doing an analysis of program code performance when written in python
> as oppose to other programming languages, and can't seem to figure out 
> why
> is the call of functions so slow?

Partly because function parameter definitions and function calls are so 
flexible.  For instance: named parameters, default values, and *seq and 
**dic parameters.

> Is a context being created and stored on stog each time

I do not know whether stog is a type or new word for me.  However, I 
believe that at present all function calls other than a generator.next 
call-after-first-yield do set up a new stack frame.  (There has been some 
discussion of some reuse in other situations also.)

> How EXACTLY does it work?

The reference manual defines that sematics that any implementation must 
implement.  'Exactly' how any particular implemention fulfills that 
contract is in the sources.

Terry J. Reedy






More information about the Python-list mailing list