IntelliJ IDEA is slow when working with Scala 3? Here is an option that fixes it

July 8, 2023

Update:latest version of Scala plugin, released on Jul 26, 2023 fixes this problem by setting Zinc compiler as default.

After the transition from Scala 2.13 to Scala 3 there were a few things that did bother me. One of them was significantly degraded performance of the IntelliJ IDEA. It felt like my MacBook Pro with M1 Pro processor was again an Intel-based laptop, everything was sluggish, IntelliJ was marking some valid code as if it was containing errors, and I was often forced to recompile project, after which errors would normally disappear. Recompilation by itself was taking more time than I used to using Scala 2.13. It really felt like the tooling is not on par with what I used to. And it turned out there was a single option, pretty much a hidden gem in the settings, that changed that experience to much better: backend for incremental compilation of Scala code.

IntelliJ IDEA uses incremental compiler to highlight the code and check it‘s validity. And by default, IntelliJ uses the old internal Incremental Compiler, which is not optimized for Scala 3. Another option that is available is Zinc compiler, which is waaay faster and is used behind SBT and other tools. To set Zinc as default, you need to go into Settings -> Build, Execution, Deployment -> Compiler -> Scala Compilerand set Incrementality typeoption to “Zinc”:

After doing that, full rebuild of the project is needed. This change did a massive upgrade of performance for me: full compilation of relatively small project (~100 Scala files) was taking 28 seconds with IDEA compiler, and is now taking only 16 seconds with Zinc. Incremental compilation now takes around 1,5 seconds, while it was taking ~2.5–5 seconds before. Apart from that, there is less “false errors” — highlights, that do disappear after recompilation, so overall the coding experience is much better now.

You can ask why it’s not a default option? Actually, there is a ticket from 9th of March in IntelliJ IDEA issue tracker to set it as default, so hopefully Zinc will become a default in near future, but you can speed up things by already doing it now!

Comments