@inline and @specialized: What do they do? Should I be using them?
summary
Explains how Scala and the JVM actually inline and specialize: HotSpot inlines hot small methods so annotating with @inline usually isn’t necessary, and disabling inlining makes the FFT benchmark 3-4x slower. Scala 2.12’s new backend yields about a 10% speedup. @specialized generates multiple versions (up to 10^n classes for n type parameters) to avoid boxing; benchmarks on a bloom filter show little short-term gain but long-term GC and primitive-array locality can matter. Useful tools: JITWatch and compiler flags like -optimize and -Yinline-warnings.
AI-written summary · about
chapters (8)
- 0:00Introduction to optimization
- 3:38Inlining explained
- 14:00Inlining in Scala
- 19:50Benchmarks for inlining
- 24:12Generics and boxing
- 30:00Specialization in Scala
- 36:40Specialization benchmarks
- 40:44Conclusion and final tips








