I'm not sure how it would terminate sort early, my initial assumption was that for small arrays there might be special-casing?
this seems to be a related thread on twitter:
Are you unsure about the runtime considerations or how the compiler would infer the necessary optimizations?
Re:GraalVM
by innagadadavida on Monday August 10, 2020 @10:50AM
(#24109853)
Can the storage of generic containers change as well? For example, store the objects in the container instead of reference?
(For an example, see some of the optimizations done by TruffleRuby for things like `myArray.sort.first` - which it apparently optimizes by terminating the sort as soon as the first element is sorted to the front of the array... and all that without any special hints in the standard library. Please correct me if I’m wrong... it’s been a few years since I’ve read in depth about TruffleRuby. And granted this example isn’t Java, but I imagine there are great parallels there.)