Reflection in Kotlin is a powerful mechanism to introspect program behavior during its execution at run-time. However, among the variety of practical tasks involving reflection, there are scenarios when the poor performance of run-time approaches becomes a significant disadvantage. This problem manifests itself in Kotless, a popular framework for developing serverless applications, because the faster the applications launch, the less their cloud infrastructure costs. In this paper, we present Reflekt - a compile-time reflection library which allows to perform the search among classes, object expressions (which in Kotlin are implemented as singleton classes), and functions in Kotlin code based on the given search query. It comes with a convenient DSL and better performance comparing to the existing run-time reflection approaches. Our experiments show that replacing run-time reflection calls with Reflekt in serverless applications created with Kotless resulted in a significant performance boost in start-up time of these applications.
翻译:科特林的反射是一个强大的机制, 用于在运行时检查程序执行过程中的程序行为。 但是, 在涉及反射的各种实际任务中, 存在运行时方法的不良性能变得非常不利的情况。 这个问题表现在 Kotless 上, 这是开发无服务器应用程序的流行框架, 因为应用程序的启动速度越快, 云层基础设施的成本就越低 。 在本文中, 我们介绍 Reflekt - 一个可进行分类搜索、 对象表达式( 在科特林作为单吨级执行) 和基于给定搜索查询的科特林代码函数。 与现有的运行时反射方法相比, 它带来一个方便的 DSL 和更好的性能。 我们的实验显示, 与 Reflekt 取代运行时的反射电话, 以无服务器应用程序创建的, Kotless 导致这些应用程序启动时间的显著的性能增强 。