Proposal: ArrayList constructor perforrmance improvement
jason_mehrens at hotmail.com
Tue Dec 18 21:49:10 UTC 2018
The reason the patched code is faster is because it will avoid an array resize that is triggered in the benchmark by:
"// once a new ArrayList is created add a new element
If you look at the patch, it is over provisioning the backing array by using "elements.length" (elementData = new Object[((ArrayList)c).elementData.length];)
instead of "size". The toArray call uses size and then the benchmark adds one element to trigger the resize.
Not sure if over provisioning the backing array is the right choice. I tend to lean towards the current paradigm of exact sizing on copy.
More information about the core-libs-dev