JDK-8145742 : Slow compilation with combination of overloading, generics, and type inference
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 8u66
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_8
  • CPU: x86
  • Submitted: 2015-12-11
  • Updated: 2016-06-01
  • Resolved: 2015-12-18
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_66"
Java(TM) SE Runtime Environment (build 1.8.0_66-b18)
Java HotSpot(TM) 64-Bit Server VM (build 25.66-b18, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.3.9600]

A DESCRIPTION OF THE PROBLEM :
When using an API that makes use of heavy overloading, lots of generics and type inference, javac can take extreme compilation times for trivial classes.

A full description is available here:
http://stackoverflow.com/q/34223249/521799

REGRESSION.  Last worked in version 7u76

ADDITIONAL REGRESSION INFORMATION: 
java version "1.7.0_67"
Java(TM) SE Runtime Environment (build 1.7.0_67-b01)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Maven is not relevant for this bug, but the following pom.xml helps reproduce it more easily:

<project 
        xmlns="http://maven.apache.org/POM/4.0.0" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
                            http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>compilation-issues</groupId>
    <artifactId>compilation-issues</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <build>
        <sourceDirectory>src</sourceDirectory>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.3</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>org.jooq</groupId>
            <artifactId>jooq</artifactId>
            <version>3.7.1</version>
        </dependency>
    </dependencies>
</project>

With the above Maven config, try compiling the following class that makes use of the jOOQ API:

import static org.jooq.impl.DSL.field;

import org.jooq.SQLDialect;
import org.jooq.impl.DSL;

public class Test {
    public void method() {
        DSL.using(SQLDialect.MYSQL)
           .select()
           .where(DSL.trueCondition())
           .and(field("client.id").eq(field("client_id")))
           .and(field("client.id").eq(field("client_id")))
           .and(field("client.id").eq(field("client_id")))
           .and(field("client.id").eq(field("client_id")))
           .and(field("client.id").eq(field("client_id")))
           .and(field("client.id").eq(field("client_id")))
           .and(field("client.id").eq(field("client_id")))
           .and(field("client.id").eq(field("client_id")))
           .and(field("client.id").eq(field("client_id")))
           .and(field("client.id").eq(field("client_id")))
        ;
    }
}

See also: http://stackoverflow.com/q/34223249/521799

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The code should compile instantly.
ACTUAL -
It takes 22 seconds on my machine. Adding more ".and(...)" clauses to the statement makes things worse and worse

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
See steps to reproduce and http://stackoverflow.com/q/34223249/521799
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
- Downgrading jOOQ to version 3.5.x
- Downgrading Java to 1.7
- Using the Eclipse compiler
- Any of the following equivalent classes, that don't rely as heavily on type inference:

import static org.jooq.impl.DSL.field;

import org.jooq.Field;
import org.jooq.SQLDialect;
import org.jooq.impl.DSL;

public class Test {
    public void method() {
        Field<Object> f1 = field("client.id");
        Field<Object> f2 = field("client_id");
        DSL.using(SQLDialect.MYSQL)
           .select()
           .where(DSL.trueCondition())
           .and(f1.eq(f2))
           .and(f1.eq(f2))
           .and(f1.eq(f2))
           .and(f1.eq(f2))
           .and(f1.eq(f2))
           .and(f1.eq(f2))
           .and(f1.eq(f2))
           .and(f1.eq(f2))
           .and(f1.eq(f2))
           .and(f1.eq(f2))
        ;
    }
}


or:


import static org.jooq.impl.DSL.field;

import org.jooq.Condition;
import org.jooq.SQLDialect;
import org.jooq.impl.DSL;

public class Test {
    public void method() {
        Condition condition = field("client.id").eq(field("client_id"));
        DSL.using(SQLDialect.MYSQL)
           .select()
           .where(DSL.trueCondition())
           .and(condition)
           .and(condition)
           .and(condition)
           .and(condition)
           .and(condition)
           .and(condition)
           .and(condition)
           .and(condition)
           .and(condition)
           .and(condition)
        ;
    }
}

See also: http://stackoverflow.com/q/34223249/521799


Comments
On a recent JDK 9 build, compilation time is reduced from 20seconds down to less than a second.
18-12-2015

This issue is duplicate of JEP - JDK-8051946
18-12-2015