Kotlin uses runtime statements to check for zero - service overhead?

I am looking at Kotlin for a simulation framework and noticed that the compiler interlaces static checkParameterIsNotNull calls after each method that can be accessed from java. This checks to see if the method parameter is null by calling (and pumping out?) The call stack every time this method is run. Now that the number of runs in a typical simulation structure can be in millions, I’m wondering about the performance impact of such a function.

If possible, disable it?

+7
performance kotlin simulation
source share
1 answer

First of all, the call stack is not accessed and is not reset every time the method starts. During normal execution, only one zero check is performed, which has no noticeable overhead. The call stack is accessed only when the parameter is null and an exception must be thrown.

Claims are not generated for private methods (because they cannot be called from Java code, and the Kotlin compiler ensures that the Kotlin code calling the method does not miss any null values). Therefore, the best way to avoid overhead is to write the inner loop of your simulation code using private methods.

You can disable claim generation by using the -Xno-param-assertions and -Xno-call-assertions for the command line compiler. Please note that these options are not supported and may be removed in the future.

+17
source share

All Articles