::scr horns of a dilemma
Simon Kinahan
scr@thegestalt.org
Fri, 29 Mar 2002 20:38:10 -0000
> > Java is not, in general, interpreted, and OO languages are no heavier
than
> > non-oo languages in any fundamental way.
>
> Not convinced. Adding a vtable to support inheritance and stuff adds a
> layer of indirection to any calls into objects. Minor, but it's
> there. At least between C and C++.
It depends. Java doesn't use vtables for private, static or final methods,
and similar is true in C++. Even when they are used, the dynamic compiler in
the VM will often inline the method call in the most common case.
The other thing to bear in mind is that while a non-optimised virtual method
dispatch is slower than a simple method call, it is quicker than a long if
{} else if{} else {} statement, or switch.
In compute benchmarks, VM-based OO languages with a dynamic compiler have
been known to beat C implementations for speed. That, admittedly, is a
fluke, but the difference in runtimes is a usually a matter of a few
percent, rather than orders of magnitude.
Simon