https://kotlinlang.org logo
#k2-early-adopters
Title
# k2-early-adopters
m

Mona Abdelaleim

10/05/2023, 3:21 PM
Hi, How to instrument compiler plugins in K2? We would like to profile kotlin compilation and to understand how long does every compiler plugin take to execute. We are already doing that for K1 (implementations details are below) and we will highly appreciate any advices on how to implement it in K2 In K1, there is the following available: 1. For monitoring compiler extension point performance. We created a compiler plugin with two extensions per extension point: one with LoadingOrder.First and the other with LoadingOrder.Last. In each method, we logged our location. 2. For the execution time of each compiler plugin, we can create a base class to log before and after each method call. For example, in the AnalysisHandlerExtension, which has only two methods (doAnalysis and AnalysisCompleted), we can log at the start and end of each call to calculate the total time spent in the extension. However, in K2, we encounter two challenges: 1. LoadingOrder for extension points is no longer available. Is there a guaranteed order for plugin execution if we arrange them in a specific order? 2. Within a single extension point, there are numerous checkers each called separately. Is there a defined order for their execution, and how continuous are these calls? Ideally, we want to measure the total time consumed by the plugin without logging each individual call. For example in the analysis phase, there are ~20 declaration checkers and ~30 expression checkers. Is there a way to collect telemetry data for the compiler as a whole?
d

dmitriy.novozhilov

10/06/2023, 7:19 AM
LoadingOrder for extension points is no longer available. Is there a guaranteed order for plugin execution if we arrange them in a specific order?
Ordering of extensions will be addressed after 2.0 release in 2.1 timeframe, see KT-55300
Within a single extension point, there are numerous checkers each called separately. Is there a defined order for their execution, and how continuous are these calls? Ideally, we want to measure the total time consumed by the plugin without logging each individual call. For example in the analysis phase, there are ~20 declaration checkers and ~30 expression checkers.
In compiler checkers are grouped by type of element they check and run on each matching element in the following order IRRC: common compiler checkers -> platform compiler checkers -> plugin compiler checkers in order of plugins registration But because of this grouping different checkers may run different number of times depending on user code which is being compiled
Is there a way to collect telemetry data for the compiler as a whole?
There is no builtin compiler mechanisms for it, but I can recommend to use async profiler and analyze its data. From my experience its most precise and easy way to inspect compiler performance
👍 1
j

Javier

10/06/2023, 7:35 AM
Ordering of extensions
Does this mean compiler plugin ordering or any extension order from any compiler plugin?
m

Mona Abdelaleim

10/06/2023, 10:09 AM
in order of plugins registration
Does this mean, if I register a plugin at the beginning, it is the equivalent to having all its extension points as LoadingOrder.First?
d

dmitriy.novozhilov

10/06/2023, 10:10 AM
Does this mean compiler plugin ordering or any extension order from any compiler plugin?
There was no design yet, so maybe both
Does this mean, if I register a plugin at the beginning, it is the equivalent to having all its extension points as LoadingOrder.First?
Yes, it should work
👍 1
5 Views