why is python slow?

Erno Kuusela erno-news at erno.iki.fi
Sat Mar 9 09:09:20 EST 2002


In article <B8AEE297.4C02%pereira at cis.upenn.edu>, Fernando Pereira
<pereira at cis.upenn.edu> writes:

| On 3/8/02 12:19 PM, in article kuelivht8g.fsf at lasipalatsi.fi, "Erno Kuusela"
| <erno-news at erno.iki.fi> wrote:

|| In article <B8AE231F.4AF0%pereira at cis.upenn.edu>, Fernando Pereira
|| <pereira at cis.upenn.edu> writes:
|| 
|| | Another reason is that a JIT compiler may not help Python as much as Java,
|| | because [...]
|| 
|| i think the last time there was an in-depth thread about this, many
|| people speculated that a jit compiler could infact help python a lot.
|| (perhaps a jit compiler can help java even more.)
|| smalltalk and self implementation techniques were discussed.

| The irreducible fact is that Python needs extensive runtime type checks,
| Java doesn't.

yes, java has an advantage in this respect. but still, there is no
reason to abandon the idea, since people have previously been
quite succesful in making dynamically typed languages execute faster
than python currently does.

i think one optimization was that you dynamically profile the
execution of the program and see if some functions always (or almost always)
get the same type of arguments. then you compile a native code
equivalent of the function that assumes those frequently encountered
types, with a check in the beginning for the mispredicted types case.

(for some functions i think it might hep if you take the call site
into account, so you'd have a (call site, function) -> optimized-code
mapping.)

i'm sure there are many more techniques, this is just one that i
happen to remember and which seems it could offer a large speedup.

  -- erno






More information about the Python-list mailing list