Skip to content

Commit

Permalink
Micro-optimizations!
Browse files Browse the repository at this point in the history
1. We were doing some expensive String-building stuff inside calls to logger.debug(), and even when that wasn't our log level we still had to pay the cost. We now check about that before actually building the strings.

2. Simplified string comparison to ignore case rather than explicitly lower-casing, which at least makes the code a little simpler
  • Loading branch information
stevenbedrick committed May 13, 2023
1 parent b628466 commit 87c9405
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions src/main/java/gov/nih/nlm/nls/metamap/lite/VariantLookupIVF.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,18 @@ public int lookupVariant(String term, String word)
logger.debug("term: " + term);
logger.debug("word: " + word);
for (String[] varFields: this.getVariantsForTerm(term.toLowerCase())) {
if ((varFields[2].toLowerCase().equals(word.toLowerCase())) ||
(varFields[2].toLowerCase().equals(term.toLowerCase()))) {
if ((varFields[2].equalsIgnoreCase(word)) ||
(varFields[2].equalsIgnoreCase(term))) {
variance = Integer.parseInt(varFields[4]); // use varlevel field
logger.debug("*varFields: " + Arrays.stream(varFields).map(i -> i.toString()).collect(Collectors.joining("|")));
if (logger.isDebugEnabled()) {
// No need to pay for expensive string building operation here unless we actually want to
logger.debug("*varFields: " + Arrays.stream(varFields).map(i -> i).collect(Collectors.joining("|")));
}
} else {
logger.debug(" varFields: " + Arrays.stream(varFields).map(i -> i.toString()).collect(Collectors.joining("|")));
if (logger.isDebugEnabled()) {
// No need to pay for expensive string building operation here unless we actually want to
logger.debug(" varFields: " + Arrays.stream(varFields).map(i -> i).collect(Collectors.joining("|")));
}
}
}
} catch (IOException ioe) {
Expand All @@ -104,11 +110,17 @@ public int lookupVariant(String term) {
try {
logger.debug("term: " + term);
for (String[] varFields: this.getVariantsForTerm(term.toLowerCase())) {
if ((varFields[2].toLowerCase().equals(term.toLowerCase()))) {
if ((varFields[2].equalsIgnoreCase(term))) {
variance = Integer.parseInt(varFields[4]); // use varlevel field
logger.debug("*varFields: " + Arrays.stream(varFields).map(i -> i.toString()).collect(Collectors.joining("|")));
if (logger.isDebugEnabled()) {
// No need to pay for expensive string building operation here unless we actually want to
logger.debug("*varFields: " + Arrays.stream(varFields).map(i -> i).collect(Collectors.joining("|")));
}
} else {
logger.debug(" varFields: " + Arrays.stream(varFields).map(i -> i.toString()).collect(Collectors.joining("|")));
if (logger.isDebugEnabled()) {
// No need to pay for expensive string building operation here unless we actually want to
logger.debug(" varFields: " + Arrays.stream(varFields).map(i -> i).collect(Collectors.joining("|")));
}
}
}
} catch (IOException ioe) {
Expand Down

0 comments on commit 87c9405

Please sign in to comment.