RFR: 8325679: Optimize ArrayList subList sort
Stuart Marks
smarks at openjdk.org
Tue Feb 13 03:58:07 UTC 2024
On Mon, 12 Feb 2024 22:52:51 GMT, Attila Szegedi <attila at openjdk.org> wrote:
> Somewhat surprisingly, `ArrayList$Sublist.sort()` is not specialized and will thus fall back to slower default method of `List.sort()` instead of sorting a range of the array in-place in its backing root `ArrayList`.
>
> This doesn't change observable behavior, so haven't added tests, and `tier1` tests still all pass except for `test/jdk/java/util/Locale/LocaleProvidersFormat.java` which also currently fails on master too on the machine I tested on.
@szegedi Oh interesting catch. Looks like a reasonable optimization. Is this covered by a test, or should a new test be added?
@JimLaskey The `List.sort` method was added in JDK 8, so not really day one. Prior to that one had to call `Collections.sort` which copied to a temp array, sorted, then copied back; this applied equally to full lists and sublists. Since JDK 8, `ArrayList.sort` on the full list did sorting in place but sorting a subList just inherited the default method (which uses the old copy-to-temp-and-sort technique). My guess is that nobody noticed this because sublists aren't used that much, and sorting of subarrays, while arguably necessary for completeness, probably aren't used all that much either.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/17818#issuecomment-1940384762
More information about the core-libs-dev
mailing list