python philosophical question - strong vs duck typing

Lie Ryan lie.1296 at
Tue Jan 10 08:05:36 EST 2012

On 01/09/2012 04:35 PM, John Nagle wrote:
> A type-inferring compiler has to analyze the whole program at
> once, because the type of a function's arguments is determined
> by its callers. This is slow. The alternative is to guess
> what the type of something is likely to be, compile code at
> run time, and be prepared to back out a bad guess. This
> requires a very complex system, but that's how PyPy does it.
> Performance does not seem to reach Shed Skin levels.

With a smart enough compiler, JIT compiler can actually be faster than 
compile-time optimizations; the reason being that different people might 
use the same code differently. For example, say we have a function that 
takes an array of numbers which can be integer or float or a mix of 
integers and floats. A compile-time optimizer cannot optimize this 
function safely; but a run-time optimizer might notice that a certain 
user only ever use the function with an array of integers and generate 
an optimized code for that particular case.

Profile-guided optimizations (PGO) can do something similar, but then it 
means a single program will have to have twenty different binaries for 
twenty different use cases; or a very large binary that contains code 
optimized for every possible thing.

More information about the Python-list mailing list