Before 2.8, the scala compiler compiled generic classes using type erasure, just like Java. However, there is a significant performance drop for primitive types: in order to satisfy the JVM requirements, primitive values need to be boxed when they enter generic code.
Boxing means wrapping a primitive value in a heap-allocated object. Whenever code operates on such values, it needs first to extract the value from the object, operate on it, then box it back.
Specialization ensures that boxing does not happen, by generating specialized versions of generic code.
Performance improvements may reach an order of magnitude.
In this talk Iulian will look at several specialized classes in the standard library, he will explain how specialization works, the benefits and some potential traps.
YOU MAY ALSO LIKE:
- Lightning Talk - 5 Things You Need to Know About Scala Compilation: #3 Will Blow Your Mind! (SkillsCast recorded in December 2017)
- Beyond Java 8 with Ben Evans (Online Workshop on 18th - 19th November 2022)
- ScalaCon 2022: Opening Keynote Networking Party (in London on 4th October 2022)
- ScalaCon 2022 (Online Conference on 4th - 8th October 2022)
- Team Topology - Enablement mode (Online Meetup on 6th October 2022)
- LJC: Monitoring Digital Experience to Determine Feature Effectiveness (Online Meetup on 11th October 2022)
- Uh, Does This Thing Actually Work? Modern Microservices Testing (SkillsCast recorded in August 2022)
- How to Contribute to Java and Open Source Projects (SkillsCast recorded in August 2022)
Scala - Performance improvements of a factor of 4 to 30, Boxing and Specialization
Iulian Dragoș dreams about a world where the Scala programming language is the default choice for new projects. He learned Scala by writing the compiler backend for it during his PhD at EPFL, back in 2004, and he was the first employee of Lightbend (formerly Typesafe). At Lightbend he helped the company grow from 5 to 85 employees, playing the role of engineer, technical lead, consultant, trainer or sales engineer. Iulian is a frequent speaker at conferences and actively contributing to several open-source projects.