[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: objective-c: how slow ?
Re: objective-c: how slow ?
Sat, 01 Sep 2001 00:56:17 -0400
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.3) Gecko/20010801
Erik M. Buck wrote:
Objective-C message dispatch is 2-3 times slower than a C function call.
Since not that much time is spent in function calls themselves as opposed to
the bodies of the functions, it seldom has a huge impact.
That depends on the programming style. In pure OOP languages like smalltalk
message passing IS the body of the functions.
Since Objective-C has hardwired control structures (from C), doesn't need to
handle integers though objects, it can have bodies that directly contain
"primitive" operations, explicitly programmed (as opposed to inlines by the
compiler). The impact of a slower dispatch isn't so great so it may be ignored,
but this situation may influence the design and coding decisions, for
example trying to avoid too deep message chains. (doubling the dispatch speed
will double the acceptable chain length, which as a design pattern
it's limited by the human creativity and should not be limited by processing
speed, if possible)
This can make the code hard to mantain in big projects, when someone
breaks the rule that in a collection should go only instances of class x.
sending within a loop, the message can be hand optimized into a simple
function call and have exactly the same performance as C.
You loose the polymorhism.
With Polymorphic inline caches you'd get the same performance as
indirect function calls and a code that will work even if one object
out of a million is of another class.
NeXT used Objective-C for writing kernel level drivers. There is no real
problem using Objective-C in a performance sensitive embedded system.
However, it would be very difficult if not impossible to prove the
determinism of the Objective-C message dispatch (since it uses hash tables),
so if you need determinism (i.e guaranteed execution time measured in CPU
clock ticks) then you don't want Objective-C.
I personally have never seen Java perform even half as fast as Objective-C.
Every Java program I have used on the desktop suffered from slow buggy
graphics and was prone to occasional halts/freezes presumably while garbage
was collected. Every Java implementation that I have seen as suffered from
a large memory footprint for the VM and then problems resulting from the
heap size not being large enough (Java heap sizes are limited for security
so that a Java program can not crash a machine by allocating too much
memory: (This is a job of the operating system and not a language, but what
can you do ?)
I didn't manage to run a Java app more than 10 minutes of work.
I don't know why companies like oracle use it as the installation &
configuration tool ! They even provide their own jdk bundled on the CD,
and it doesn't run either or when it runs (it depends on the moon, it seems)
it (jre) ates 1GB of ram for the installation (512 KB of ram, 512 of swap, I
Java I really an unhappy example, though.
With the HotSpot compiler (developed as part of the Self project at Sun) Java
could theoreticy be very fast and responsive.
But Java is a bad crossing of two world, a bad balance of runtime and
compiletime. I think that all this was imposed by marketing rules,
because Java had to be similar to C++ and must run safely on various
OS, each of them with security problems and limited common memory management
Objective-C is also a hybrid but a well-though one.
The performance of the gui is surprising. Certainly
this is also because of the OpenStep desing (I had to run on a 33Mhz 68k),
but also the raw power of objc.
There are a couple of issues I don't like, mostly
the very verbose naming of methods (I really like the at:put: stuff from
smalltalk), but I understand that there is no way out, the signature
must be unique for a selector if it handles primitive types.
Objc has many drawbacks, many of which roots in C.
I'd like to put itegers in collections without wrappers, use
closures for actions, gracefully handle integer overflows, have
nil a real object, having real class object with metaclasses, ...
But for me OpenStep matters, not objc itself; changing objc
doesn't make sense. Adding a bit of performance, maybe.
Do you think that doubling the performance of message dispatch for common
targets will speedup the gui (responsivness) ?