mattisonchao commented on pull request #10986:
URL: https://github.com/apache/pulsar/pull/10986#issuecomment-870939519


   > Did you see some measurable improvement?
   > 
   > I am saying this because recently JVM handle string concatenation better 
that using StringBuilder in same cases and forcing a concatenation strategy 
sometimes it is not the best option.
   > 
   > That said I am not against this change, but I just want to know if this is 
the result of some static code analysis or it is fixing a real problem. You 
know the motto 'don't fix things that are not broken
   
   But if you try to connect String in a loop, they will create a lot of 
StringBuilder Object.
   the bytecode is as follows:
   
   ```java
    L0
       LINENUMBER 6 L0
       LDC "abc"
       ASTORE 1
      L1
       LINENUMBER 7 L1
       ICONST_0
       ISTORE 2
      L2
      FRAME APPEND [java/lang/String I]
       ILOAD 2
       BIPUSH 10
       IF_ICMPGE L3
      L4
       LINENUMBER 8 L4
       NEW java/lang/StringBuilder
       DUP
       INVOKESPECIAL java/lang/StringBuilder.<init> ()V
       ALOAD 1
       INVOKEVIRTUAL java/lang/StringBuilder.append 
(Ljava/lang/String;)Ljava/lang/StringBuilder;
       LDC "d"
       INVOKEVIRTUAL java/lang/StringBuilder.append 
(Ljava/lang/String;)Ljava/lang/StringBuilder;
       INVOKEVIRTUAL java/lang/StringBuilder.toString ()Ljava/lang/String;
       ASTORE 1
      L5
       LINENUMBER 7 L5
       IINC 2 1
       GOTO L2
      L3
       LINENUMBER 10 L3
      FRAME CHOP 1
       GETSTATIC java/lang/System.out : Ljava/io/PrintStream;
       ALOAD 1
       INVOKEVIRTUAL java/io/PrintStream.println (Ljava/lang/String;)V
      L6
       LINENUMBER 11 L6
       RETURN
      L7
       LOCALVARIABLE i I L2 L3 2
       LOCALVARIABLE args [Ljava/lang/String; L0 L7 0
       LOCALVARIABLE a Ljava/lang/String; L1 L7 1
       MAXSTACK = 2
       MAXLOCALS = 3
   ```


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to