GeeCON Prague 2014*
The moose likes Performance and the fly likes Auto-boxing/Auto-Unboxing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Performance
Bookmark "Auto-boxing/Auto-Unboxing" Watch "Auto-boxing/Auto-Unboxing" New topic
Author

Auto-boxing/Auto-Unboxing

Shameer Subedar
Greenhorn

Joined: Apr 08, 2004
Posts: 22
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
Alan Moore
Ranch Hand

Joined: May 06, 2004
Posts: 262
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.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
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.


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
 
GeeCON Prague 2014
 
subject: Auto-boxing/Auto-Unboxing