Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java object initialization with diamond operator terrible javac compile time performance

I'm using the diamond operator to initiate objects within a list. However as the number of array objects increases, compile time increases from few seconds to hours. My eclipse auto build made my eclipse non-responsive. I then noticed it is a javac issue. When I replace all <> with <String, List<Category>> the compile time goes back to just a few seconds. Is this something I'm doing wrong or is it just a Java performance issue?

Here is my code which will take Java hours to compile (or crashes javac v8u25):

    List<Pair<String, List<Category>>> categoryMappings = null;

    public void reloadStaticData() {                  
      // Left one is the provider's category and right one is ours
      try(UoW luow = CoreModule.getInstance(UoW.class)) {
        CategoryRepo categoryRepo = luow.getCategoryRepo();
        categoryMappings = Arrays.asList(

                  // Nightlife
                  new ImmutablePair<>("Bars", Arrays.asList(categoryRepo.findByName("Bar & Pubs").get())),
                  new ImmutablePair<>("Ski-Bar", Arrays.asList(categoryRepo.findByName("Bar & Pubs").get())),
                  new ImmutablePair<>("Bar", Arrays.asList(categoryRepo.findByName("Bar & Pubs").get())),
                  new ImmutablePair<>("Beer", Arrays.asList(categoryRepo.findByName("Bar & Pubs").get())),
                  new ImmutablePair<>("Pubs", Arrays.asList(categoryRepo.findByName("Bar & Pubs").get())),
                  new ImmutablePair<>("Clubs", Arrays.asList(categoryRepo.findByName("Bar & Pubs").get())),
                  new ImmutablePair<>("Dance", Arrays.asList(categoryRepo.findByName("Bar & Pubs").get()
                          ,categoryRepo.findByName("Clubs").get())),    
                  // if I got more than 20 of these ImmutablePairs, javac crashes or takes hours to compile
      );
      }
    }

Edit: As Sotirios mentioned in comments it seems to be a reported issue in JDK:

type inference exponential compilation performance: https://bugs.openjdk.java.net/browse/JDK-8055984

type inference performance regression: https://bugs.openjdk.java.net/browse/JDK-8048838

like image 867
Jimmy Page Avatar asked Jan 04 '15 16:01

Jimmy Page


1 Answers

I'm currently working on JEP-215 Tiered attribution. The goal of this JEP is to improve the attribution code in javac, and as a side effect to improve the compiler's performance. For example the code listed in bug JDK-8055984 is compiled by "normal" Javac9 in: a lot of time! The current version of tiered attribution compiles it in ~2.5 seconds, which is much better. Tiered attribution's code is not public yet. I hope it will be so soon. In the meantime this kind or reports are really useful.

Edit: if anyone want to give a try to tiered attribution, still in development, please check this announcement: tiered attribution for all

like image 131
Vicente Romero Avatar answered Oct 19 '22 21:10

Vicente Romero