I created two separate functions to test if SonarQube can detect performance issues. First one is an infinite loop and second function takes lot of time to execute.
## Function 1
## Function 2
result = ""
for i in range(1000):
result += str(i)
# Call the function
result_string = concatenate_strings_performance_issue()
It is surprising that SonarQube didn’t detect any performance issues with both of these functions. Any idea why?
Hello Tinku and welcome to the community!
I really appreciate the value that issues around infinite loops should be detected if they’re unintended, however, that intent is difficult to ascertain. Do you have some real-world code examples of unintended infinite loops? Where we see them in the wild, they are intended (eg event listening) and artificial examples do not really make it clear how this kind of issue could happen unintentionally. We do have a rule in a similar spirit, but focused on recursion, but it is not free of false-positive reports.
Similarly, the performance example does have the same challenge - a real-world example where the unintended performance issue is clear would help. Our goal would be to ensure that the rule is not noisy. Having said this, we are looking into performance rules for Python generally, and you can follow the progress here.