Slow kotlin sensor

Hello, since the end of November, we’ve seen a regression in sonar analysis performances while analyzing our Android app.
It looks like the scanner is stuck on one file for a few minutes before checking the other files:

15:42:59.983 INFO  0/5445 files analyzed, current file: data/models/ActionType.kt
15:43:09.983 INFO  0/5445 files analyzed, current file: data/models/ActionType.kt
15:43:19.983 INFO  0/5445 files analyzed, current file: data/models/ActionType.kt
15:43:29.983 INFO  0/5445 files analyzed, current file: data/models/ActionType.kt
15:43:39.983 INFO  0/5445 files analyzed, current file: data/models/ActionType.kt
15:43:49.984 INFO  0/5445 files analyzed, current file: data/models/ActionType.kt
15:43:59.984 INFO  0/5445 files analyzed, current file: data/models/ActionType.kt
15:44:09.984 INFO  0/5445 files analyzed, current file: data/models/ActionType.kt
15:44:19.984 INFO  0/5445 files analyzed, current file: data/models/ActionType.kt
15:44:29.985 INFO  0/5445 files analyzed, current file: data/models/ActionType.kt
15:44:39.985 INFO  0/5445 files analyzed, current file: data/models/ActionType.kt
15:44:49.985 INFO  0/5445 files analyzed, current file: data/models/ActionType.kt
15:44:59.986 INFO  0/5445 files analyzed, current file: data/models/ActionType.kt
15:45:09.986 INFO  0/5445 files analyzed, current file: data/models/ActionType.kt
15:45:19.986 INFO  0/5445 files analyzed, current file: data/models/ActionType.kt
15:45:30.035 INFO  0/5445 files analyzed, current file: data/models/ActionType.kt
15:45:40.029 INFO  151/5445 files analyzed, current file: features/ViewModel.kt
15:45:50.029 INFO  1013/5445 files analyzed, current file: features/Module.kt

Previous analysis took ~30s and now it’s ~4min.

Hey @le.flow

How are you analyzing your code? Specifically, which Scanner are you using?

I’ve been told that with the updates made to our Kotlin analyzer, analysis can be slow if using the SonarScaner CLI (in which all code is analyzed as a single module), but the performance is better using the Scanner for Maven or Scanner for Gradle.

Hi Colin,

I’m using the sonar scanner CLI.
I’ll try out the Gradle plugin, but I’m concerned that it might be slower due to the Gradle configuration process being very slow on our project.

With the next release of the analyzer (where we switch to the new compiler frontend K2) the analysis must become faster.

As for the Gradle, Gradle scanner takes into account your modules structure and it’s classpath. If you’re using the scanner-cli you either have to pass this information manually or you might have imprecisions in the analysis results.

The main issue with using scanner-cli with Gradle multi-module project is that it is assumed to be a single module and building the Semantic for it takes much more time (this is what you see in the analysis results). Previously, there was a fallback to not generate semantic module if there’s no classpath, so the analysis was fast but results where imprecise as 80% of our rules require semantic model.

With migration to the new Kotlin Analysis API, this fallback was removed as it’s incompatible with the new Kotlin compiler.

To wrap up, we still recommend you to use Gradle scanner to have proper analysis. Try it and let us know if your performance concern is still valid. And anyway with the next release (will reach SC next week) the analysis must become faster.

Best,
Margarita

Hi Margarita,

Thank you for the explanation; it’s clear.

I’ll need some time to try the Gradle scanner. In the meantime, I’ve managed to use the scanner only on modified files, which makes it faster for small PRs and helps mitigate the issue.