From: Chris Gehlker Date: 2002-02-18T10:31:18+09:00 Subject: Re: OOP overhead (Was: tiny contest...) On 2/17/02 3:45 PM, "Sean Russell" wrote: > Richard Harlos wrote: > .... >> My refactoring eliminated redundant instances of code, shrinking the >> source file considerably. I also implemented a rather straight-forward >> API so that this routine could be easily implemented generically rather >> than for just a few specific clients. > .... >> Sadly, in almost every case the performance increase is significant. >> >> Just my 2 cents, for what it's worth :-) > > I'll add another 2 cents to yours. > > Refactoring and increasing the OO of nearly anything will increase the > time. Method calls are expensive, and so is object creation; as long as > this is true, OO with minimal redundant code will always be slower than, > say, procedural programming. > > That said, speed isn't OO's strength: maintainability and reuse are. And > if you've got good design and style, it can be easier to understand code > you haven't seen before. While I agree with the thrust of Sean's comment, I have to quibble with a detail. The degree of overhead that one pays for OO is very language dependent. If we can agree for sake of argument that C++ is an OO language, despite what Alan Kay said, then the cost of a method call is one extra address lookup and the cost of object creation is not that much higher than initializing a struct. In ObjC the first time you call a method it's expensive but thereafter the address is cached and it's fairly cheap. To put this in some kind of perspective, I program on the PPC and the current release version of gcc there generates prolog and epilog code for every C call to leaf functions that moves the contents of registers to the stack and then back again. This elaborate no-op costs more than method dispatch. So moving to a developmental version of gcc or to Motorola's compiler buys you a lot more than OO costs you. -- Conversation, n. A fair for the display of the minor mental commodities, each exhibitor being too intent upon the arrangement of his own wares to observe those of his neighbor. -Ambrose Bierce