carterkozak commented on a change in pull request #555: URL: https://github.com/apache/logging-log4j2/pull/555#discussion_r682086487
########## File path: log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/NameAbbreviator.java ########## @@ -285,40 +285,40 @@ public PatternAbbreviatorFragment( /** * Abbreviate element of name. * - * @param buf buffer to receive element. - * @param startPos starting index of name element. - * @return starting index of next element. + * @param input input string which is being written to the output {@code buf}. + * @param inputIndex starting index of name element in the {@code input} string. + * @param buf buffer to receive element. + * @return starting index of next element. */ - public int abbreviate(final StringBuilder buf, final int startPos) { - final int start = (startPos < 0) ? 0 : startPos; - final int max = buf.length(); - int nextDot = -1; - for (int i = start; i < max; i++) { - if (buf.charAt(i) == '.') { - nextDot = i; - break; - } + int abbreviate(final String input, final int inputIndex, final StringBuilder buf) { + // ckozak: indexOf with a string is intentional. indexOf(String, int) appears to + // have optimizations that don't apply to indexOf(char, int) + // which result in a >10% performance improvement in some + // NamePatternConverterBenchmark cases. This should be re-evaluated with + // future java releases. + int nextDot = input.indexOf(".", inputIndex); + if (nextDot < 0) { + buf.append(input, inputIndex, input.length()); + return nextDot; } - if (nextDot != -1) { - if (nextDot - startPos > charCount) { - buf.delete(startPos + charCount, nextDot); Review comment: This line as well as the `buf.insert` on 308 are potentially costly because they shift the entire buffer beyond the deleted/inserted position. Small buffers are relatively inexpensive because everything fits nicely in cache, but larger values will have non-obvious performance problems. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org