Skip to content

Logger/string formatting slows down some calculations #789

@biocryst

Description

@biocryst

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:

logger.debug(" cccc: " + one.getResidueNumber() +
" " + one.getPDBName() + " " +two.getResidueNumber()+
" " + two.getPDBName() + String.format(" O ("+
O.getPDBserial()+")..N ("+ N.getPDBserial()+
"):%4.1f | ho:%4.1f - hc:%4.1f + nc:%4.1f - no:%4.1f ",
dno,dho,dhc,dnc,dno));

logger.debug(String.format(" N (%d) O(%d): %4.1f : %4.2f ",
N.getPDBserial(),O.getPDBserial(), (float) dno, energy));

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugBugs and bugfixesenhancementImprovement of existing code or method

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions