Reputation: 45
I am interested in understanding important Java coding rules from the performance point of view. Also, if someone has already tried putting these rules in a static code analyzer like Sonar for static code inspection.
Please pour in your views or any suggestions.
Regards,
Xhings
Upvotes: 4
Views: 2792
Reputation: 2135
Performance is dynamic characteristic, so it is difficult to spot it in static analysis. You never know regarding the performance. The general observation in the industry is '80% of CPU is consumed by 20% of code'. Very frequently it is even more imbalanced than that. And it is almost impossible to predict the location of this 20% spot in advance. Sometimes it is even difficult to find it using dynamic analysis (due to lack of right profiling test-scenarios, which are close to real production scenarios). However, Intel Amplifier XE in light-weight hotspots mode can (usually) profile real production deployments. Worth trying.
Upvotes: 0
Reputation: 18458
Findbug, is the bug detection tool used in Sonar. It has category for performance. You could create ruleset just including only the performance ones. For example
SBSC: Method concatenates strings using + in a loop
Side note : Static code analysis will be of limited help to identify bottleneck. You will have to use real performance analysis tools (like VisualVM, JProfiler or YourKit ) for identifying areas of improvements.
Upvotes: 1