carterkozak commented on a change in pull request #555:
URL: https://github.com/apache/logging-log4j2/pull/555#discussion_r683429654



##########
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);

Review comment:
       Great find! I really appreciate your insight, @schlosna. I'll a/b test 
on jdk16 to see how performance is impacted. If the character search is much 
better, it might be worthwhile to use that as it should stand the test of time, 
especially with jdk17 right around the corner.




-- 
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


Reply via email to