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
Joined: May 06, 2004
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.
Joined: Jul 11, 2001
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