Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8333462

Performance regression of new DecimalFormat() when compare to jdk11

XMLWordPrintable

    • 17
    • b26
    • generic
    • generic

        Create behalf on lingjun.cg@alibaba-inc.com

        Run the following benchmark in Linux with 8C32G, it shows poor performance of the new DecimalFormat() when compared to jdk11.
        ```
        @BenchmarkMode(Mode.AverageTime)
        @Warmup(iterations = 5, time = 500, timeUnit = TimeUnit.MILLISECONDS)
        @Measurement(iterations = 10, time = 500, timeUnit = TimeUnit.MILLISECONDS)
        @State(Scope.Thread)
        @OutputTimeUnit(TimeUnit.NANOSECONDS)
        public class JmhDecimalFormat {

            @Setup(Level.Trial)
            public void setup() {
            }

            @Benchmark
            public void testNewOnly() throws InterruptedException {
                new DecimalFormat("#0.00000");
            }
        }
        ```

        the result with jdk 11:
        Benchmark Mode Cnt Score Error Units
        JmhDecimalFormat.testNewOnly avgt 50 248.300 ? 5.158 ns/op


        the result with current jdk:
        Benchmark Mode Cnt Score Error Units
        JmhDecimalFormat.testNewOnly avgt 50 303.381 ? 5.252 ns/op


        When run the other test case to get the flame graph:
        ```
        import java.text.DecimalFormat;
        public class DecimalTest {
            private static long start;
            private static long end;
            public static void main(String[] args) {
                start = System.currentTimeMillis();
                int count = Integer.parseInt(args[0]);
                DecimalFormat format;
                for(int i = 0 ; i < count; i++) {
                    format = new DecimalFormat("#0.00000");
                }
                end = System.currentTimeMillis();
                System.out.println("Cost " + (end-start) +" ms");
            }
        }
        ```

        Compare the flame graph between JDK 11 and JDK 21, it shows "java/util/stream/IntPipeline.findFirst"
        task extra 15% CPU time.

              syan Sendao Yan
              syan Sendao Yan
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Created:
                Updated:
                Resolved: