Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upLogger/string formatting slows down some calculations #789
Comments
|
Good catch! Indeed this shows how careful use of the loggers is very important. So reminder for everyone: please always use string substitution: logger.debug("The value of var is {}", var);in favor of concatenation: logger.debug("The value of var is " + var);Reference: https://www.slf4j.org/faq.html#logging_performance |
|
Should we search systematically for string concatenations or String.format calls in logging statements? |
|
Sonarqube is a pretty good tool for finding such things as well as a plethora of other coding bugs, smells and other faux-pas. It's a little depressing running it on a codebase for the first time, but overall it's a pretty good tool to keep code clean and use best practices. It could be set up similar to the Travis build where code bellow a certain quality is blocked from merging. |
|
Yes, Sonarqube is indeed a great tool. We are actually trying it right now for other projects. I'm going to give SonarCloud a try in BioJava as soon as I can. |
Calculating secondary structure of 4hhb 10000 times takes 589 seconds on my machine. If the following two lines are commented out, it takes 34 seconds:
biojava/biojava-structure/src/main/java/org/biojava/nbio/structure/secstruc/SecStrucCalc.java
Lines 851 to 856 in 8a7b651
biojava/biojava-structure/src/main/java/org/biojava/nbio/structure/secstruc/SecStrucCalc.java
Lines 869 to 870 in 8a7b651
The problem is likely to be in the String.format method. Using SLF4J parameterized messages instead ("{}") is much faster, but does not support float formatting to number of decimal places (see https://stackoverflow.com/questions/22720865/formatting-floating-point-numbers-in-slf4j, thanks @josemduarte ).
My suggestion is to go through the logging messages which use string formatting and, if feasible, change them to parameterized messages.
The performance is noticeably affected only if the logging statements are somewhere deep within a loop.