# Porting the Scala 2 optimizer to Scala 3

DevFeed: [Porting the Scala 2 optimizer to Scala 3](<https://devfeed.tech/articles/porting-the-scala-2-optimizer-to-scala-3-43560.md>)

Original publisher: [Read original article](<https://www.scala-lang.org/blog/2026/03/23/porting-the-optimizer.html>)

Published: 2026-03-22T23:00:00Z

Content type: article

Language: en

Sources: [The Scala Programming Language](<https://devfeed.tech/sources/the-scala-programming-language.md>)

Topics: [Scala](<https://devfeed.tech/topics/scala.md>), [Compiler](<https://devfeed.tech/topics/compiler.md>), [Closure](<https://devfeed.tech/topics/closure.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [compiler](<https://devfeed.tech/tags/compiler.md>), [functional](<https://devfeed.tech/tags/functional.md>), [performance](<https://devfeed.tech/tags/performance.md>), [scala](<https://devfeed.tech/tags/scala.md>), [scala-3](<https://devfeed.tech/tags/scala-3.md>)

## AI overview

This post explains the work to port the Scala 2 optimizer to the Scala 3 compiler. The goal is to improve the performance of high-level functional Scala code without requiring developers to write more complex low-level code; early microbenchmarks reported 10-30% faster execution.

## Source excerpt

This post covers work done under the Sovereign Tech Fund investment umbrella: Maintenance of the Standard Library/Core Library Modules and APIs. The work is coordinated by the Scala Center. We are porting the optimizer from the Scala 2 compiler to the Scala 3 compiler, improving the performance of Scala 3 applications without requiring developers to write more complex code. In early microbenchmarks of code written in a high-level functional style, we're seeing 10-30% faster execution. But what exactly is this optimizer and why is it necessary? This work is available as of version 3.8.3-RC3 of the Scala compiler. Scala is a modern and concise language, meaning you can write code expressing what you want to do by composing primitives, rather than how to do it step-by-step. High-level code is easier to read and maintain, in addition to being shorter to write. Scala's expressiveness enables you to write what you mean: def addOneMap(a: Array[Int]) = a.map(_ + 1) However, from a CPU's point of view, a high-level API like map is conceptually more complex than the equivalent low-level code. It's a function call that is passed another function, leading to a "megamorphic" call site that is harder for the JVM to optimize, and the function argument might need a closure to be allocated on the heap if it captures local values. Compiled naïvely, the high-level call wouldn't be as fast as this equivalent low-level loop: def addOneLoop(a: Array[Int]) = val l = a.length val r = new Array[Int](l) var i = 0 while i < l do r(i) = a(i) + 1 i += 1 r You don't want to write this loop, because its purpose is a lot less obvious and it is harder to maintain, but without compiler help, you might have to write it if that function is critical to your application's performance. (Why would adding one to an array be critical to your app's performance? Because you're reading a pedagogical blog post and thus suspending disbelief!) If you've ever written a map function yourself, you may recognize the