mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 23:04:50 +02:00
8222852: Reduce String concat combinator tree shapes by folding constants into prependers
Co-authored-by: Peter Levart <peter.levart@gmail.com> Reviewed-by: shade, plevart, forax
This commit is contained in:
parent
e3aa6f7907
commit
e7a6cbbd38
5 changed files with 293 additions and 100 deletions
|
@ -26,6 +26,7 @@ import org.openjdk.jmh.annotations.Benchmark;
|
|||
import org.openjdk.jmh.annotations.BenchmarkMode;
|
||||
import org.openjdk.jmh.annotations.Mode;
|
||||
import org.openjdk.jmh.annotations.OutputTimeUnit;
|
||||
import org.openjdk.jmh.annotations.Param;
|
||||
import org.openjdk.jmh.annotations.Scope;
|
||||
import org.openjdk.jmh.annotations.Setup;
|
||||
import org.openjdk.jmh.annotations.State;
|
||||
|
@ -42,7 +43,8 @@ import java.util.concurrent.TimeUnit;
|
|||
@State(Scope.Thread)
|
||||
public class StringConcat {
|
||||
|
||||
public int intValue = 4711;
|
||||
@Param("4711")
|
||||
public int intValue;
|
||||
|
||||
public String stringValue = String.valueOf(intValue);
|
||||
|
||||
|
@ -77,11 +79,26 @@ public class StringConcat {
|
|||
return "string" + stringValue + "string" + intValue;
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public String concatMix4String() {
|
||||
// Investigate "profile pollution" between shared LFs that might eliminate some JIT optimizations
|
||||
String s1 = "string" + stringValue + stringValue + stringValue + stringValue;
|
||||
String s2 = "string" + stringValue + "string" + stringValue + stringValue + stringValue;
|
||||
String s3 = stringValue + stringValue + "string" + stringValue + "string" + stringValue + "string";
|
||||
String s4 = "string" + stringValue + "string" + stringValue + "string" + stringValue + "string" + stringValue + "string";
|
||||
return s1 + s2 + s3 + s4;
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public String concatConst4String() {
|
||||
return "string" + stringValue + stringValue + stringValue + stringValue;
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public String concat4String() {
|
||||
return stringValue + stringValue + stringValue + stringValue;
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public String concatConst2String() {
|
||||
return "string" + stringValue + stringValue;
|
||||
|
@ -97,6 +114,11 @@ public class StringConcat {
|
|||
return "string" + stringValue + stringValue + stringValue + stringValue + stringValue + stringValue;
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public String concat6String() {
|
||||
return stringValue + stringValue + stringValue + stringValue + stringValue + stringValue;
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public String concatConst6Object() {
|
||||
return "string" + objectValue + objectValue + objectValue + objectValue + objectValue + objectValue;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue