RFR: 8305774: String.join(CharSequence, Iterable) can be optimized if Iterable is a Collection [v2]

Chen Liang liach at openjdk.org
Mon Apr 10 03:06:42 UTC 2023


On Sun, 9 Apr 2023 02:37:45 GMT, Tingjun Yuan <duke at openjdk.org> wrote:

>> 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?
>
> @liach Working on that.

@yuantj Alternatively, you can probably try working on the `toArray` result of a collection than to allocate a new String array. This might be more efficient for some implementations like ArrayList as well, in addition to benefiting concurrent collections.

-------------

PR Comment: https://git.openjdk.org/jdk/pull/13383#issuecomment-1501331722


More information about the core-libs-dev mailing list