How expensive is type inference?

scala

Solution

Scala’s elaborate and powerful types exist only(*) during compilation time: they are parsed from source (where you give them), inferred, checked and then, finally, discarded. The last may sound nonsensical, but it is the modus operandi of the JVM (see type erasure) and quite useful from a language designer’s viewpoint.

So, to answer your question: at runtime it makes no difference whether the type was explicitly given or inferred, the only difference is in how long it takes to compile the program.

(*) The 2.10 release will come with a reflection library which allows the program to access its type information also at runtime; this gives added freedom—which if used will of course burn CPU cycles at runtime—but does not change any of the aforementioned points.

Problem

I am definitely more than thrilled with the Scala type inference engine, but in a real world environment: How much of a performance draw back is it? When is the type inferred, at compile time or runtime?

Original source

Related problems