Asserting Kotlin Image Processing (KSP) Alpha

Posted by Ting-Yuan Huang‎, Software program Engineer and David Winer, Product Supervisor

Android image

At the moment we’re excited to announce the alpha of Kotlin Image Processing (KSP), an all-new instrument for constructing light-weight compiler plugins in Kotlin. KSP affords comparable performance to KAPT, nonetheless it’s as much as 2x sooner, affords direct entry to Kotlin compiler options, and is being developed with multiplatform compatibility in thoughts.

KSP is suitable with the Kotlin 1.4.30 launch and onwards. You possibly can try the open supply code and documentation within the KSP GitHub repository.

Why KSP?

The #1 request we hear from Kotlin builders is to make construct speeds sooner. Many builders iterate on and deploy apps dozens of occasions a day, so having to sit down round ready for a sluggish construct will be very time consuming. One of many largest challenges with compiling Kotlin code is that Kotlin doesn’t have a local annotation processing system. Annotation processors like Room are ubiquitous on Android and depend on Java annotation processing compatibility via the Kotlin Annotation Processing Software (KAPT). KAPT will be sluggish to run, although, because it requires producing intermediate Java stubs that may then be ingested by the Java annotation processing system.

When designing KSP, we thought of what annotation processing would seem like for Kotlin if we constructed it from the bottom up. KSP affords a robust and but easy API for parsing Kotlin code immediately, dramatically lowering the construct pace tax imposed by KAPT’s stub era. Certainly, preliminary benchmarks with the Room library present that KSP is roughly 2x sooner than KAPT.

Getting began

To see what KSP seems to be like in motion, obtain the KSP playground project from GitHub. In it you’ll discover:

  • Library: A toy test-processor library that implements the builder sample as a KSP processor
  • Consuming challenge: A workload listing that reveals find out how to use the builder processor in a real-world Kotlin challenge

The entire logic for implementing the builder is in test-processor — for the patron (workload), the one distinction between utilizing KAPT and KSP is a two-line construct file change:

That is the aim of KSP: most Android app builders don’t want to fret about its internals; apart from this one line change, a library that helps KSP seems to be similar to a traditional annotation processor, solely it’s as much as 2x sooner. That stated, utilizing KAPT and KSP in the identical module will probably decelerate your construct initially, so throughout this alpha interval, it’s best to make use of KSP and KAPT in separate modules.

As extra annotation processors undertake KSP, we count on most of your modules to have the ability to use KSP as a close to drop-in alternative for KAPT. For now, you possibly can try which annotation processors provide KSP assist in this table. If a library that helps or is implementing assist for KSP is lacking from the desk, please submit a pull request along with your suggestion!

If you’re an creator of a library that presently makes use of annotation processing, yow will discover extra info on find out how to make your library suitable with KSP within the quickstart and README guides.

For library authors, now that KSP is in alpha, it’s a good time to start out trying intently at it and giving us suggestions on the API within the KSP issue tracker. As well as, we frequently publish launch updates within the #ksp channel on Kotlin Slack. For the reason that developer preview final June, we’ve closed over 100 bugs and points, dozens of which have been reported by the wonderful neighborhood of Kotlin library builders.

Java is a registered trademark of Oracle and/or its associates.

Recent Articles

Get enjoying with one of the best video games for PlayStation Now

Supply: Android Central Greatest Video games for PlayStation Now Android Central 2021 PlayStation Now is a large service today, with over 800 games in its library and a few...

Android Studio 4.2

Posted by Jamal Eason, Product Supervisor, Android We're excited to announce that Android Studio 4.2 is now accessible to obtain within the...

Related Stories

Stay on op - Ge the daily news in your inbox