[ann] Minimal Python project

Peter Hansen peter at engcorp.com
Sat Jan 11 17:57:01 EST 2003


"Edward K. Ream" wrote:
> 
> > > If JIT's are so effective, why are the swing classes so slow?
> >
> > Think of how slow they'd be without the JIT compilers! After all,
> > they're doing in Java what any sane package does in C with
> > assembler assists.
> 
> I am _not_ denying that JIT's can speed up code!  I am raising doubts about
> whether any JIT can produce results superior to hand-written C code.  The
> two issues are completely different!

I believe it's actually not the case that a JIT compiler will generally
produce faster code than hand-written C.  JIT compilers have a trade-off
between speed of the generated code, and speed of the code generation --
they must finish quickly because they have to run at startup.

As I understand it, a compiler like the Java HotSpot compiler, however, 
*can* produce results better than hand-written C, and the reason should 
be fairly clear:  in addition to having more time to execute because it
doesn't reduce invocation time, a compiler like that has the advantage
of being able to analyze the code *in the current dynamic context*
where it is running.  The C compiler has no knowledge of the conditions
that will exist when the code runs.  Even if it did, its job is
already done, while the HotSpot compiler can run again, and again,
tuning the application as conditions change.

Now if you want to argue *still* that hand-written C code based 
on a careful analysis of the dynamic situation to be expected,
and designed automatically to adapt as conditions change can always
be made faster than what something like HotSpot can produce, then
I would say you're making the same argument I made 23 years ago
about Assembler versus optimizing C compilers, and the answer 
is the same: *practically* it's irrelevant because only in extremely
rare circumstances can one afford to take the time to optimize
or design that carefully, while the HotSpot compiler can do it
in general "for free".

-Peter




More information about the Python-list mailing list