Hi Kevin,
If you google for specialization in Scala you'll find a number of
pages that explain it in detail.
The basic idea is that the part you are talking about is just an
annotation on T -- it should behave more of less the same as code
without that annotation. The difference is that specialization will
create variants of this class to handle the different primitive
types, to avoid boxing.
In Java (and so on the JVM), there is a distinction between "double"
(a primitive type), and "java.lang.Double" (a boxed type). The
primitive types are stack allocated, are not garbage-collected, and
can be operated on (e.g. added) directly. The boxed values are
allocated and freed by GC, and wrap an actual "double" value.
In Scala "Double" is a separate concept that encompasses both "double"
and "java.lang.Double". In the context of Scala generics, "Double"
usually means "java.lang.Double" but specialization is a way to create
a code path specific to "double" to avoid this boxing.
Hopefully this gives you enough context to learn more about the
feature. It is somewhat mysterious, buggy, and complicated, but right
now it's a very necessary part of getting the performance we need out
of Spire's type classes.
-- Erik
On Tue, Apr 21, 2015 at 08:22:24AM -0700, Kevin Meredith wrote:
> Looking at Complex.scala
> <
https://github.com/non/spire/blob/master/core/src/main/scala/spire/math/Complex.scala#L91>
> :