New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create an extension point at rule execution to measure performances #6962
Comments
It's great to see someone interested on this topic! I think that the performance on a static analysis tool is key. It is the main reason to don't use it or use it less times. About your proposal: that should be easy to implement. But I think that a feature like that should be inside detekt. I would love to have to receive issues related with the performance on specific rules so we can fix them. So, would you be willing to implement that inside detekt? My problem to implement it is how to handle all that information. |
I feel the same way! I run detekt and ktlint. What is interesting is that ktlint, even with many more rules enabled, runs like 10 times as fast for me. So I am very curious what is happening. I can think of some ideas for handling the information. I will be happy to give this a shot. |
Is it ok if develop this on top of 3flex's k2 branch instead of main so that I can work in k2? Or would that make the PR too complicated? |
Why do you want to do that? From my side, how you develop it is up to you. But to merge your branch you should rebase it back to main or wait for that other branch to be merged (aka wait for kotlin 2.0).
Right now if you enable the debug mode on detekt
If they are ready to imminent you can just go for it. Otherwise I recommend you to share them to see if they align with our ideas. That would probably make the pr review faster. |
Thank you for clarifying. I will see what is the best way for me than, but in the end will merge it back to main or wait before submitting a PR. As for why, just because I am using K2 in general so it is less context switching.
I didn't know about this. I tried it, and the results were interesting.
I ran detekt on one of my multiplatform modules which contains source sets for jvm, android, js, and native. The debug info printed 12 times, and since I have the worker API enabled I am guessing it printed once per worker. Here are a couple of examples:
As you can see, the Binding phase either was super fast or super slow. So I am guessing that binding is either enabled or disabled depending on the target? Is that right? About half of them seemed to have a long Binding phase. But Parsing was consistently long, and might have contributed the highest amount to the total time as a result.
After seeing the debug information above, my idea is we start with the existing scaffolding of the debug option.
We could also see:
This would make the debug print a lot more, but that seems ok to me because it is "debug" after all and it is disabled by default.
Also, side question, I see lots of messages in my debug output like:
Is this normal? Is it due to running detekt on non-jvm sources? Should I do something about it? |
It prints it once per detekt task. Even without the worker API that would happen.
You are right.
That have sense. And I don't see how can we make that faster. The only tool that I can think of is parallelization. I was thinking about using coroutines inside detekt but probably that's not the main priority right now.
Right now
Yes, that's normal. And there is nothing we can do right now to fix that. Maybe 2.0 would help us there, no idea. The tasks where the Binding phase was SUPER quick you will see that messages. |
Is Parsing done in the same task as running rules? Parsing depends only on the source code. It doesn't depend on things used for rule execution such as the detekt configuration file and the detekt classpath for custom rules and extensions. So I am wondering if the Parsing phase could be put into a separate task. That way it will not have to rerun if a developer only edits their Detekt config file, for example.
It is already parallel if the gradle build itself is parallel though, right? So I think parallelizing more would not benefit projects that are already parallel, and therefore are already at CPU capacity. Detekt is not IO-bound, right?
What is a "matrix file x rule"? While technically not a blocker, I would prefer to wait for #6715 to be fixed before I start this so that I'm able to develop this while testing it on my full project. |
It is. And there is no way to split those because the result of parsing is not serializable to a file. Well, that "serialization" is the Kotlin file itself.
Well, it's parallel by gradle project. But a gradle project have several files. Those files could be parsed in parallel. But I'm not sure if that would make detekt faster.
No idea, I assume that a some stages yes. For example, parsing, as it needs to read every single file on the project.
I was thinking of something like a csv. Each row is a file, each column is a rule. And each cell is the time expended by that rule in that file. |
I would like to measure the performance of rules. I can measure the time it takes to process a file with the
FileProcessListener
extension point. But I do not see an extension point for rules.I suggest something like:
detekt/detekt-core/src/main/kotlin/io/gitlab/arturbosch/detekt/core/Analyzer.kt
Line 139 in bc83921
For my use case, which is just to measure time, I do not need the list of findings.
Based on idea from @arturbosch here #5183. Also might solve that issue.
The text was updated successfully, but these errors were encountered: