File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Performance and the fly likes what is effect of object oriented on performance? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Performance
Bookmark "what is effect of object oriented on performance?" Watch "what is effect of object oriented on performance?" New topic
Author

what is effect of object oriented on performance?

raminaa niilian
Ranch Hand

Joined: Jul 14, 2005
Posts: 551
Hi
Thank you for reading my post.
is there any side effect on performance of a system because of using OO ?
for example inheritance and so on?

Thanks
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Sure there are side effects. They are non-trivial, in both directions, and most often negligible.

Why do you ask?


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

This sorta sidesteps the question, but the biggest concern, and cost, associated with any commercial, enterprise application, is its long-term maintainability and sustainability. A well designed OO application is much more maintainable, understandable, and sustainable. This applies equally to an application that relies heavily on automated testing as well.

-Cameron McKenzie
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
There is some overhead to dynamic dispatch of methods. Most OO compilers optimize this well enough that we can usually ignore it. See Virtual Method Table.

Years ago there were heated debates on various VTable algorithms. Microsoft and Borland and other vendors leaprfrogged each other's performance on every release. There was an argument that executing some code in a superclass and some in a subclass forced long jumps instead of short jumps (on Intel anyhow) and greatly increased the probablility of paging. Yawn. Modern compilers and processors and cheap memory have made almost all of this worry go away.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Stan James:
There is some overhead to dynamic dispatch of methods.


Note that the alternative to dynamic dispatch are if- or switch-statements, which arguably have a similar overhead.
steve souza
Ranch Hand

Joined: Jun 26, 2002
Posts: 860
I really think answering these questions does a disservice to the poster.


http://www.jamonapi.com/ - a fast, free open source performance tuning api.
JavaRanch Performance FAQ
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by steve souza:
I really think answering these questions does a disservice to the poster.


So what alternative do you suggest? Want to serve as a good example?
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
If only there were a good tool for actually measuring performance, rather than indulging in meaningless speculations based on vague generalizations...


"I'm not back." - Bill Harding, Twister
steve souza
Ranch Hand

Joined: Jun 26, 2002
Posts: 860
So what alternative do you suggest? Want to serve as a good example?


The question is immaterial because the performance gains to be had by such microtuning are typically minimal compared to overall application performance. If posters insist on microtuning we should tell them how to measure the performance themselves (i.e. teach them to fish), and let them post the answer. The best service we can provide to junior developers is to get them into the habit of monitoring their code and tuning where appropriate, and not just randomly tuning their code based on whim.

I provided a similar answer in the following faq. Answering such questions with a link to the faq would be appropriate.

I have a link for performance faq's at the bottom of all of my postings. Maybe there could be a whiddled down version for micotuning questions. Item 13 in the faq addresses this in an admittedly harsh way.


12) Don't microtune - An example of microtuning is when you have a web page that takes 1 second to execute, and you notice that you can tune a subset of this pages code and reduce this subsets execution time from 20 ms. to 10 ms. Congratulations, you've cut the execution time of this code in half! This sounds impressive, until you realize you have only trimmed the performance of your overall page by 1% (from 1000 ms. to 990 ms).

This tuning was a waste of time. Your time would have been better spent drinking a beer. Look for changes that give you the biggest bang for your tuning buck.

13) There are bad Performance Tuning Questions - The most common performance tuning questions I see on the java forums are purely academic, and make no substantive difference in real programs. Questions like: "Are statics faster than instance variables?", "Are local variables faster than instance variables?", "Are HashMaps faster than Vectors?", "Are while loops faster than for loops?",...

When we answer such questions without stating that they are purely academic, we do a disservice to the development community by perpetuating the idea that microtuning is the place they should focus their attention.

Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Most of the answers included recommendations to ignore the effects of OO on performance and that was a good theme. A casual decision to do two database queries instead of one or to call a remote service will make far more difference than OO or not.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

You can't legitimately talk about "performance" of a piece of code A unless you have an equivalent (i.e. does exactly the same thing) piece of code B to compare it to. So asking about the performance "using OO" is meaningless unless you have an equivalent "not using OO" code that you can talk about.

But nobody has that code, because the question is too high-level for a question that must have low-level things like actual pieces of code to compare. The question is trying to apply a low-level question (performance) to a high-level concept (language design). Hence the exasperated responses from people who are attempting to craft a reply that is simultaneously accurate and polite.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: what is effect of object oriented on performance?
 
Similar Threads
Is there a performace impact for those ?
Serialization Vs Externalisation
global variables
exception handling
can i display only first few records from oracle sql