You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by GitBox <gi...@apache.org> on 2021/08/03 20:34:18 UTC

[GitHub] [logging-log4j2] garydgregory commented on a change in pull request #555: Improve worst-case NameAbbreviator performance

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



##########
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:
       I've not looked at this but the scary part to me is that the performance might vary from JRE vendor to JRE vendor and from version to version.




-- 
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-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org