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

Performance regression in JDK 21 for double arithmetic operations

XMLWordPrintable

    • x86_64
    • linux_ubuntu

      ADDITIONAL SYSTEM INFORMATION :
      # Java version
      java 21.0.6 2025-01-21 LTS
      Java(TM) SE Runtime Environment (build 21.0.6+8-LTS-188)
      Java HotSpot(TM) 64-Bit Server VM (build 21.0.6+8-LTS-188, mixed mode, sharing)

      # Operating system details
      $ cat /etc/*release
      DISTRIB_ID=Ubuntu
      DISTRIB_RELEASE=20.04
      DISTRIB_CODENAME=focal
      DISTRIB_DESCRIPTION="Ubuntu 20.04.6 LTS"
      NAME="Ubuntu"
      VERSION="20.04.6 LTS (Focal Fossa)"
      ID=ubuntu
      ID_LIKE=debian
      PRETTY_NAME="Ubuntu 20.04.6 LTS"
      VERSION_ID="20.04"
      HOME_URL="https://www.ubuntu.com/"
      SUPPORT_URL="https://help.ubuntu.com/"
      BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
      PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
      VERSION_CODENAME=focal
      UBUNTU_CODENAME=focal

      A DESCRIPTION OF THE PROBLEM :
      Performance regression in JDK 21 for double arithmetic operations
      compared to JDK 17. The issue seems to be fixed in JDK 23, but JDK 23
      is still slower than JDK 17. Similar issue in Graal: https://github.com/oracle/graal/issues/10609

      REGRESSION : Last worked in version 17.0.14

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      The issue can be reproduced by running JMH code below with different JDK versions

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      similar performance for recent JDK versions
      ACTUAL -
      JDK 17.0.12, Java HotSpot(TM) 64-Bit Server VM, 17.0.12+8-LTS-286:
      Benchmark Mode Cnt Score Error Units
      Sum.add avgt 15 9.661 ± 0.081 ns/op

      JDK 21.0.6, Java HotSpot(TM) 64-Bit Server VM, 21.0.6+8-LTS-188:
      Benchmark Mode Cnt Score Error Units
      Sum.add avgt 15 102.754 ± 0.862 ns/op

      JDK 23.0.2, Java HotSpot(TM) 64-Bit Server VM, 23.0.2+7-58:
      Benchmark Mode Cnt Score Error Units
      Sum.add avgt 15 13.110 ± 0.102 ns/op


      ---------- BEGIN SOURCE ----------
      # Sum.java
      ```java
      package org.sample;

      import org.openjdk.jmh.annotations.*;
      import java.util.concurrent.TimeUnit;

      @State(Scope.Thread)
      @BenchmarkMode(Mode.AverageTime)
      @OutputTimeUnit(TimeUnit.NANOSECONDS)
      @Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
      @Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
      @Fork(3)
      public class Sum {
          private static double sum = 1.0;
          private static double comp = 0.1;

          static double twoSumLow(double a, double b, double sum) {
              final double bVirtual = sum - a;
              return (a - (sum - bVirtual)) + (b - bVirtual);
          }

          @Benchmark
          public void add() {
              final double newSum = (sum % comp);
              comp += twoSumLow(0.1, comp, newSum);
              sum += comp;
          }
      }
      ```
      ---------- END SOURCE ----------

            dholmes David Holmes
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            10 Start watching this issue

              Created:
              Updated: