apk.fm / News / Accelerated Kotlin build times with Kotlin Symbol Processing 1.0

Accelerated Kotlin build times with Kotlin Symbol Processing 1.0


Posted by Ting-Yuan Huang, Software program Engineer and Jiaxiang Chen, Software program Engineer

Accelerated Kotlin build times with Kotlin Symbol Processing 1.0 image

Kotlin Image Processing (KSP), our new instrument for constructing light-weight compiler plugins in Kotlin, is now steady! KSP gives comparable performance to the Kotlin Annotation Processing Device (KAPT), nonetheless it’s as much as 2x quicker, gives direct entry to Kotlin language constructs, and gives assist for multiplatform targets.

Over the previous few months, KSP has gone by way of 32 releases with over 162 bugs reported from the group and stuck by our group. In case you had been ready to undertake it, now’s the time to test it out.

Why we constructed KSP

On the Android group, we recurrently ask builders: what are your largest frustrations with writing apps at this time? One of many prime points that comes up repeatedly is construct velocity. Over time we’ve been making regular enhancements to the Android construct toolchain, and at this time we’re excited so as to add to these enhancements with KSP. KSP is the following era of annotation processing in Kotlin: it should dramatically enhance construct velocity for Kotlin builders, and in contrast to KAPT, it gives assist for Kotlin/Native and Kotlin/JS.

Why is KSP quicker?

The Kotlin Annotation Processing Device (KAPT) works with Java’s annotation processing infrastructure to make most Java language annotation processors work in Kotlin out of the field. To do that, KAPT compiles Kotlin code into Java stubs that retain info that Java annotation processors care about. Creating these stubs is dear although, and means the compiler should resolve all of the symbols in your program a number of instances (as soon as to generate stubs, after which once more to do the precise compilation).

KSP strikes away from the stub era mannequin by working as a Kotlin compiler plugin — it permits annotation processors to learn and analyze source packages and assets immediately in Kotlin as an alternative of requiring you to rely upon the Java annotation processing infrastructure. This each dramatically improves construct velocity (as much as 2x quicker for Room’s Kotlin take a look at app) and implies that KSP can be utilized for non-Android and non-JVM environments like Kotlin/Native and Kotlin/JS.

Find out how to get began

To begin utilizing KSP, obtain the KSP playground mission from GitHub, which reveals use KSP each as an annotation processor and as a consuming app/library:

  • Annotation processor: A toy test-processor library that implements the builder sample as a KSP processor
  • Consuming library: A workload listing that reveals use the builder processor in a real-world Kotlin mission

In case you’re an app developer, try the record of supported libraries and the quickstart information for shifting a module over from KAPT to KSP.

Utilizing Moshi or Room with KSP

In case you’re utilizing Moshi or Room in your mission, you’ll be able to already check out KSP by making a fast repair to your module’s construct file. For instance, to make use of the KSP model of Room in a Gradle module you’ll be able to merely change the KAPT plugin with KSP and swap out the KSP dependency:

apply plugin: 'com.google.devtools.ksp'

dependencies {
  implementation "androidx.room:room-runtime:$room_version"
  kapt "androidx.room:room-compiler:$room_version"
  ksp "androidx.room:room-compiler:$room_version"


Try the Room launch notes for more information.


With the 1.0 launch of KSP you’ll begin to see improved construct instances on your Kotlin initiatives as you migrate away from libraries based mostly on KAPT. We have now additionally up to date quite a lot of Android particular libraries that are prepared so that you can attempt at this time and provide important efficiency enhancements.

Source hyperlink

Take a comment