• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Object allocation and Performance

 
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
------------------
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic