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



##########
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:
       This performance change was _wild_:
   
   ```diff
   - int nextDot = input.indexOf('.', inputIndex);
   + int nextDot = input.indexOf(".", inputIndex);
   ```
   
   @garydgregory Any chance you have ideas that might explain this? It threw me 
for a loop because the character-based indexOf underperforms compared to the 
old implementation, while the string-based indexOf has an advantage and much 
lower variance.




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