JDK-8156071 : List.of: reduce array copying during creation
  • Type: Sub-task
  • Component: core-libs
  • Sub-Component: java.util:collections
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2016-05-04
  • Updated: 2020-10-22
  • Resolved: 2020-10-05
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 16
16 b19Fixed
Description
The various fixed-arg factory methods mostly call internal varargs constructors, causing array creating and element copying. The resulting array is passed to a constructor that creates another array and copies it (or clones it) again. Consider the List.of(...) methods that call the ListN() constructor. This is quite wasteful.

A likely solution is for the fixed-arg API methods to call an internal varargs method, which can trust the array because it originated internally.

See Peter Levart's comments here:

http://mail.openjdk.java.net/pipermail/core-libs-dev/2016-May/040791.html

Comments
Changeset: 88d75c9a Author: Stuart Marks <smarks@openjdk.org> Date: 2020-10-05 17:00:57 +0000 URL: https://git.openjdk.java.net/jdk/commit/88d75c9a
05-10-2020

Similar comments apply to the new j.u.stream.Collectors.toUnmodifiableList() collector -- an extra copy is done in that case. A shared secret will probably need to be plumbed in order for the stream collectors to get access to any new private factory methods.
24-07-2020