2 ms·
Author discusses a Java 1.3 app where he saved tons of memory by reducing leaf collection sizes. I had sort of the opposite with a Java 1.2 code base. Some cle
by hinkley 7y ago
Author discusses a Java 1.3 app where he saved tons of memory by reducing leaf collection sizes.
I had sort of the opposite with a Java 1.2 code base. Some clever person has noticed that a bunch of vectors often had only 4-7 entries so they overrode the default (10) to 7. This is unfortunately greater than n/2 which will become important momentarily.
In Java collections tend to double in size on space exhaustion. Using a multiple instead of addition amortizes the insertion time to O(1). So if you start at 7, you go to 14 next.
As I’m sure you can guess, the number of entries crept up to 8 over time. Switching back to the defaults reduced the wasted space from 6 to 2 slots, and dropped our memory usage by more than 10%.