I have an application where I perform hundreds of thousands of calculations. Currently all of our values are Doubles. I am utilizing JFormula engine for most of the calculations, and have noticed the api takes a double parameter, so there is some autoboxing taking place when I pass in a Double. I have read some articles, and created some simple tests, and do notice a performance hit, but am still trying to figure out it the time it takes to go through my code and fix this, will be worth any performance improvements. I am wondering if anyone else has had any experience with something similar and performance gains by using primitives?
-
Have you profiled the code at all to see if the autoboxing stands out as an issue? – carson Oct 27 '08 at 17:58
-
No, This issue just occurred to me today as I was looking through the code. That is the next step that I was going to pursue. I just wanted to get some additional feedback. thanks, – Oct 27 '08 at 18:23
-
How much code have you written? Even in a decent-size app, I could switch from using Double to double in the time it took you to post this question! As with (almost) any optimizations, profiling is the only thing which will tell you the size of the hit, if any. – oxbow_lakes Oct 27 '08 at 21:32
3 Answers
It is not appropriate to use autoboxing and unboxing for scientific computing, or other performance-sensitive numerical code. -- Sun FAQ

- 812
- 4
- 6
-
I don't believe this is an issue for him. He is only using the wrappers to get the values to the front door. From JFormula on I would assume they are primitives or BigDecimals. – carson Oct 27 '08 at 18:43
As well as the other suggestions (which are good - profiling and benchmarking are very important) I'd say that if JFormula is doing anything significant within each method call then the boxing/unboxing when making the call is likely to be insignificant. Unboxing in particular is fast as it doesn't require any memory allocation - just copying the existing value from the box, really.
In short: certainly do the tests, but I wouldn't expect the hit to be significant.

- 1,421,763
- 867
- 9,128
- 9,194
What you can try is to make simple benchmarks with and without autoboxing. run them through a time-profiler (visualvm recommended). Find the time difference and scale it to your program to find approximate time hit in your program

- 17,454
- 22
- 87
- 114