Some specific implementations of the Java collection class because the underlying data store is based on arrays, and as the number of elements increases, the cost of resizing is significant. As the collection element grows to an upper limit, it may be possible to adjust its size to a performance issue.
When the collection element reaches the maximum value of the internal array, a new array needs to be created. and the old array elements are copied to the new array through the Arrays.copyof method, which consumes the CPU time slices and also requires garbage collection, especially when the collection object has a long life cycle and is already in the old age and needs to go through a full GC to free up memory. The memory of the new array allocates memory in the young generation's Eden area (which may not be allocated in the Eden area when the object is particularly large), and it takes two times to enter the survivor area to enter the old age, the mark of garbage collection, The performance consumed by the purge operation can be avoided at the time of initialization of the collection, given a reasonable size.
There is still a problem when resizing an array. The new copy of the array reference element may be assigned by the JVM in a location that is not in the same block memory as the other field references in the collection class, which may cause a CPU cache miss (in general, the object and its fields need to be accessed concurrently. The memory location where the object and its fields are placed in the same location as possible will increase the CPU memory hit ratio, and the time to access the field will be longer (albeit soon).
Note: This paper considers the collection class based on the array implementation, and does not discuss the chain list such as LinkedList, TREEMAP, etc.
The performance cost of the Java Collection collection class Sizing