[Python-Dev] Optimization targets
"Martin v. Löwis"
martin at v.loewis.de
Thu Apr 15 15:07:12 EDT 2004
Jeremy Hylton wrote:
> Another question that I'd love to hear the answer to: What's the
> difference between Pysco and something like this Self implementation or
> the HotSpot Java implementation?
Psyco is specializing, and that is the main difference compared
to Java Hotspot. If you have a program
def f(a, b):
if a>b:
return a
else:
return a-b
f(1,2)
f(1.0, 2.0)
f([1,2],[3,4])
then psyco generates machine code for *three* functions
int f_int(int a, int b){ // uses process int arithmethic throughout
if(a>b)return a;
else return a-b;
}
double f_double(double a, double b){ // uses FPU ops throughout
if(a>b)return a;
else return a-b;
}
list f_list(list a, list b){ // might invoke C functions
if(list_gt(a, b))return a;
else raise TypeError("unexpected operands");
}
(it actually generates different specializations)
In Hotspot, the type of f would already be defined in the Java
source code, and Hotspot generates native machine instructions
for it.
The changes over standard JIT appear to be inlining; it also
appears to do inlining of virtual functions, combined with
a type check to detect cases where the a different functions
should have been called compared to the last time the virtual
call was made.
Regards,
Martin
More information about the Python-Dev
mailing list