• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Auto-boxing/Auto-Unboxing

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I just wondering of the performance implications of using the auto boxing features. Does it matter if we allow the complier to put the smarts in or should we explicitly do the conversions ourselves ?

I am developing a real-time trading application and performance related issues are very important to us.

On a side note, having read an article in context of C# in regards to auto-boxing, they mentioned not to over use it as it may have performance issues.

Thanks in advance,
Shameer
 
Ranch Hand
Posts: 262
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the most important question is not who does the conversion, but whether the conversion needs to be done. I've seen a few examples recently of people declaring variables as, e.g., Integer or Boolean when they really mean int or boolean. In complex code, I can see this causing a lot of unncecssary conversions, and I would guess that's what that article was talking about. In general, I recommend always declaring your primitives as primitives unless you know they will only be used in an object context, like the keys in a Map. Another way to head off unintended conversions is to declare your fields, variables and parameters final whenever you can. Of course, these are things we should have been doing all along, for robustness as well as performance, but auto-boxing makes them more relevant than ever.
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with Alan - if there is a performance problem at all, it's caused by the boxing/unboxing itself, not by it being automatic instead of manual.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic