It is true that string concatenation can be a bottleneck in Java because String immutable. This means that each concatenation creates a new String , unless the corresponding String has been created and therefore is in the string pool (see string interning ). In any case, this can lead to problems.
However, your predecessor is not the first person to come across this, and the standard way to deal with the need to concatenate many String in Java is to use StringBuilder .
If a double used as a local variable (or any primitive), it is stored on the stack, and the memory it occupies is freed along with the stack frame (not sure if they are exposed to the GC or the JVM will take care of it). If, however, double is a field on the object, it is stored on the heap and will be assembled when the assembled object is assembled.
Not seeing how double values ββare used, it's hard to say for sure, but it is more likely that using Map increased the load on the GC.
So, yes, IMHO this, of course, as you say "crazy and completely unnecessary." These types of premature optimizations only complicate the code base, which makes it more error prone and makes future maintenance difficult. The golden rule should be almost always, to build the simplest thing that works, profile it and then optimize.
source share