Loading... (original) (raw)
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
)
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.