Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8193128

Reduce number of implementation classes returned by List/Set/Map.of()

XMLWordPrintable

      The static List, Set and Map factories added in 9 strike a balance between reducing footprint (by providing specialized implementations for small number of entries) and speed (using @Stable guarantees enables a JIT to constant fold). However, the number of implementation classes can have negative effects:

      - Callsites may become bi- or megamorphic that would be monomorphic if it only observed a single implementation, e.g., ArrayList.
      - Although trivially JITed, splitting work over 4 List implementation delays how quicky individual implementations reach optimal compilation levels, which can affect startup and warmup (observed after JDK-8184777)

      As such, this is part Enhancement, part Bug (observable regressions when using List.of() compared to arrays or ArrayList)

      Experiments show we can profitably reduce the number of implementation classes to 2 while remaining footprint neutral.

      We could also provide an option to only have one implementation, forfeiting the footprint gain to ensure monomorphic callsites.

            redestad Claes Redestad
            redestad Claes Redestad
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: