On Sun, 9 Apr 2023 02:28:37 GMT, Tingjun Yuan <d...@openjdk.org> wrote:
>> In the current implementation of `String.join(CharSequence, Iterable)`, the >> temp array `elems` is always initialized with a length of 8. It will cause >> many array recreations when the `Iterable` contains more than 8 elements. >> Furthermore, it's very common that an `Iterable` is also a `Collection`. So >> if the `Iterable` is an instance of `Collection`, the initial length of the >> array can be `((Collection<?>)elements).size()`. It will not change the >> current behavior even if the `Collection` is modified asynchronously. >> >> I don't know whether this change requires a CSR request. > > Tingjun Yuan has updated the pull request incrementally with one additional > commit since the last revision: > > Add benchmark This appears to be a 4% improvement for non-concurrent structures like ArrayList or LinkedHashSet, if we ignore the baseline difference (for Iterable). This is anticipated as the growth of array size is exponential, so the total allocation is effectively O(N log(N)). Can you try with smaller quantities, like single-digit or double digits length, which may be more frequent in application? ------------- PR Comment: https://git.openjdk.org/jdk/pull/13383#issuecomment-1501023576