Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Object allocation and Performance

 
Anoop Krishnan
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I herad that object allocation will reduce the performance of java application.Could you say how much and how it is happening if i creates a lot of objects eg a substring operation or a string concatenation using + operator
------------------
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Anoop Krishnan:
I herad that object allocation will reduce the performance of java application.

A couple of days ago there was a question from someone having a performance problem which he thought was caused by his database. After retrieving 1000 or so records, execution speed took a nosedive. Looking at the code, there were a few dozen string concatenations for each record! After replacing this with a StringBuffer, total execution time went down from over an hour to a couple of minutes.
Object allocation isn't so bad, but the subsequent garbage collection has a huge performance impact. That's why, in the anecdote above, performance was OK until all available memory had been used up and execution speed became constrained by how fast the garbage collector could free up memory.
It's a fact of life in Java that you tend to create fairly large amounts of short-lived objects, and generational garbage collectors in today's JVMs try to make the best of it. Still, if you are careless, performance will suffer badly.
- Peter
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!