Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what is effect of object oriented on performance?

 
raminaa niilian
Ranch Hand
Posts: 551
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure there are side effects. They are non-trivial, in both directions, and most often negligible.

Why do you ask?
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 862
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I really think answering these questions does a disservice to the poster.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If only there were a good tool for actually measuring performance, rather than indulging in meaningless speculations based on vague generalizations...
 
steve souza
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic