IntelliJ IDEA
IntelliJ IDEA – the Leading Java and Kotlin IDE, by JetBrains
Kotlin K2 Mode Becomes Stable
In IntelliJ IDEA 2024.3, K2 mode is out of Beta and is now Stable and ready for general use. K2 mode significantly improves Kotlin code analysis stability, memory consumption efficiency, and the IDE’s overall performance, and it supports Kotlin 2.1 language features.
Background
K2 mode in IntelliJ IDEA was developed to address limitations in the previous version of the Kotlin plugin, including various performance and stability issues. It aims to enhance the efficiency of the Kotlin plugin for IntelliJ IDEA by improving code analysis stability and performance while reducing UI freezes. Additionally, K2 mode enables support for new language features that will be introduced in Kotlin 2.1 and later versions.
Compatibility
IntelliJ IDEA’s K2 mode doesn’t depend on the Kotlin compiler version specified in the project’s build settings. K2 mode represents an almost complete rewrite of Kotlin support within the IDE. The name “K2” reflects that the Kotlin plugin includes an internal version of the K2 Kotlin compiler, which it uses for code analysis, while K1 mode uses the K1 compiler. The version of the Kotlin compiler bundled in IntelliJ IDEA is entirely independent of the version specified in the project’s build file, though it may affect the range of supported Kotlin versions in projects.
How to enable K2 mode
To enable K2 mode, go to Preferences/Settings | Languages & Frameworks | Kotlin and select the Enable K2 mode checkbox.
Results
Adoption
Since the 2024.2 release, K2 mode (Beta) has shown adoption rates of 15% – and this number is growing weekly. K2 mode was enabled by default starting with 2024.3 EAP 1, and 86% of developers who tried it are still using it.
Performance
With the new architecture, K2 mode has vast potential for future enhancements, and we already have improvements in Kotlin code analysis, completion, and navigation speed.
There are benchmarks that we use to measure the performance of the most popular IntelliJ IDEA features. These benchmarks work on real codebases, including open-source and internal projects. Here are some of the projects we measured the performance on:
- IntelliJ IDEA: the IntelliJ IDEA Ultimate’s source code (closed source)
- kotlinx.coroutines https://github.com/Kotlin/kotlinx.coroutines
- Ktor: https://github.com/ktorio/ktor
Below are the results. Lower is better.
Unsupported functionality
Some third-party IntelliJ IDEA plugins that depend on the Kotlin plugin may be currently unavailable because of recent changes to the Kotlin plugin API. We’re actively working on supporting plugin authors to make their plugins compatible with K2 mode as quickly as possible. For more information, please refer to our detailed migration guide.
Some functionality like Kotlin scratch file support, as well as some minor inspections, intention actions, and quick-fixes are still in progress and will be supported in the next version.
Plans for the future
By the 2025.1 version, we plan to make K2 mode the default option.
With the new architecture, we’ve broken the ceiling of previous limitations, and we now have many new ways to improve the future performance of the Kotlin plugin. We’ll continue to make it more performant, memory-efficient, and stable to make your experience smoother. While K2 mode is a powerful tool, it’s important to note that it won’t address all challenges immediately, but it does provide a great foundation from which we can make further improvements!
The future of Kotlin awaits!