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

Lambda performance degradation

XMLWordPrintable

    • x86_64
    • windows_7

      FULL PRODUCT VERSION :
      build 1.8.0_05-b13

      FULL OS VERSION :
      Windows 7 Professional, Servicepack 1

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      Reproducible via Netbeans and a clean java call from command line.

      A DESCRIPTION OF THE PROBLEM :
      The second call to the same simplest lambda function needs 40 times longer than the first one. The third even needs 70 times longer and it gets worse.

      THE PROBLEM WAS REPRODUCIBLE WITH -Xint FLAG: Did not try

      THE PROBLEM WAS REPRODUCIBLE WITH -server FLAG: Yes

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the program under "Source Code". The degradations of the same lambda calls are printed.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      Second and third call should approximately need the same time.
      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class Lambda {
          public static int res=0;
          public static void main(String[]args) {
              final int times=1_000_000_000;
              times(times, ()->res+=2, "res+=2"); // needs 48 ms
              times(times, ()->res+=2, "res+=2"); // needs 1913 ms
              times(times, ()->res+=2, "res+=2"); // needs 3381 ms
          }
          public static void times(final int times, Runnable c, String program) {
              res=0;
              long start = System.currentTimeMillis(); // TODO nanoTime()?
              for(int i=0; i<times; i++) c.run();
              System.out.format("%s times %s=%s in %s ms\n", times, program, res, System.currentTimeMillis()-start);
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      use for(int x=0; x<3; x++) times(times, ()->res+=2, "res+=2");
      instead of lambdas.


            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: