You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2021/06/29 21:40:13 UTC
[GitHub] [pulsar] mattisonchao edited a comment on pull request #10986: Fixed # fixed string concatation in loop.
mattisonchao edited a comment on pull request #10986:
URL: https://github.com/apache/pulsar/pull/10986#issuecomment-870936897
> 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
Yes, I test it in a small example. when you use a string connection inline, the JVM will translate it to `StringBuilder` and invoke the `append` method to handle it.
the bytecode is as follows:
```java
L0
LINENUMBER 6 L0
LDC "abc"
ASTORE 1
L1
LINENUMBER 7 L1
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
L2
LINENUMBER 10 L2
GETSTATIC java/lang/System.out : Ljava/io/PrintStream;
ALOAD 1
INVOKEVIRTUAL java/io/PrintStream.println (Ljava/lang/String;)V
L3
LINENUMBER 11 L3
RETURN
L4
LOCALVARIABLE args [Ljava/lang/String; L0 L4 0
LOCALVARIABLE a Ljava/lang/String; L1 L4 1
MAXSTACK = 2
MAXLOCALS = 2
```
--
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: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org