Static fields and specialization

Palo Marton palo.marton at gmail.com
Mon Jan 12 11:44:09 UTC 2015


Yes, but you can not create specialized implementations for user defined
value types. So these will be left with much slower implementation.
Singleton implementation compiles to just 0-1 instructions and
implementation that allocates new instance will be much slower.

And other problem - such approach is against goals of specialization: You
will have to write separate code for each primitive type.

Pavol Marton, aSc
www.asctimetables.com


> In the case of Optional.empty() and others like Collections.emptyList()
> it's a method that you're invoking. There is no need to implement static
> field specialization. You can just get your specialized implementations to
> return different singleton instances. Ok - so this means you now have 9
> empty instances rather than 1 but that's basically nothing in terms of
> memory consumption. In the case of Optional you already have manual
> specialisation for 3 primitive cases in the form of Optionalint and friends
> so its really 9 rather than 4 anyway.
>
> regards,
>
>   Richard Warburton
>
>   http://insightfullogic.com
>   @RichardWarburto <http://twitter.com/richardwarburto>
>



More information about the valhalla-dev mailing list