Kotlin symbol processing (KSP) alpha is now available

Time:2021-9-12

Kotlin symbol processing (KSP) alpha is now available

Author / Software Engineer Ting yuan Huang and product manager David winer

We are pleased to introduce youKotlin Symbol Processing(KSP), a new tool to help you build lightweight compiler plug-ins in kotlin. KSP provides functions similar toKAPTHowever, the speed is increased by 2 times, the kotlin compiler function can be accessed directly, and the multi platform compatibility is fully considered during development.

KSP is compatible with kotlin version 1.4.30 and later. You canKSP GitHub repoView open source and documentation in.

Why KSP?

Kotlin developers give us the most feedback on the need to improve the construction speed. Many developers have to iterate and deploy applications dozens of times a day, so the slow construction speed will make developers have to spend a lot of time waiting. One of the biggest challenges in compiling kotlin code is that kotlin does not have a native annotation processing system. such asRoomAnnotation processors such as are ubiquitous on the Android platform, and they rely on Java annotation processing compatibility through the kotlin annotation processing tool (kapt). However, kapt may run slowly because it needs to generate intermediate Java stubs before the Java annotation processing system can extract them.

When designing KSP, we considered what form kotlin’s annotation processing should be if we build it from scratch. KSP provides a powerful and simple API, which can directly parse kotlin code, so it greatly reduces the construction speed burden caused by kapt generating stubs. In fact, the initial benchmark performed with the room library showed that KSP was about twice as fast as kapt.

Start using

To view the actual operation of KSP, please download it from GitHubKSP playground project。 You can get:

  • library: a small test processor library that implements the builder pattern as a KSP processor
  • Use item: shows how to use the workload directory of the builder processor in an actual kotlin project

All the logic to implement the builder is in the test processor – for the workload, the only difference between using kapt and using KSP is that two lines of build file have been changed:

Kotlin symbol processing (KSP) alpha is now available

This is the goal of KSP: most Android application developers don’t have to worry about their internal structure; In addition to this line change, KSP enabled libraries are similar to ordinary annotation processors, but the speed is twice as fast. That is to say the first mock exam of KAPT and KSP in the same module will reduce the speed of your building, so it is better to use KSP and KAPT in the separate modules during the Alpha version.

As more and more annotation processors adopt KSP, we hope that most of your modules can use KSP to directly replace kapt. Now you canformSee which annotation processors provide KSP support. If there is no library that has been supported or is implementing KSP support in the table, please feed back your valuable suggestions to us!

If you are the author of a library that uses annotation processing, you canquick get startandREADMEFind more information on how to make your library compatible with KSP in the guide.

For library authors, KSP’s current alpha version is a good opportunity for in-depth research. Welcome toKSP problem trackerProvides us with feedback on the API. In addition, we will be in the official account of Google developers.Kotlin SlackRelease version dynamics regularly on the #ksp channel of. Since the release of the developer preview in June last year, we have solved more than 100 errors and problems, dozens of which have been fed back by the excellent kotlin library developer community. I hope you can continue to pass the questionKSP problem trackerGive us feedback or leave a message at the bottom of the article.

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

Recommended Today

Detailed steps for installing Perl and Komodo IDE for windows

Perl official website: https://www.perl.org/Perl document: https://perldoc.perl.org/Download address: https://www.perl.org/get.html The installation package of Perl Windows version is divided into activestate Perl and strawberry Perl. For the difference between the two, see: http://www.zzvips.com/article/202134.htm Note: the download speed of activestate Perl is slow. You may need KX to surf the Internet I have uploaded all the versions of […]