title: Troubleshoot slow compilation
body: <p><strong>What should I do to investigate and troubleshoot a slow compilation problem</strong>?</p>
  <p>My project has about 100 classes and takes more than 45 seconds to compile, which seems very slow to me. As a reference, I have another project with 50 classes that compiles in 3 seconds.</p>
  <p>ps:</p>
  <ul>
  <li>I use maven as a build tool. It takes maven ~50 seconds to compile (<code>mvn clean compile</code>), of which 45 seconds are spent running javac (confirmed by running with the <code>-X</code> option).</li>
  <li>increasing the amount of memory did not help (<code>-Xms500m</code>)</li>
  <li>I can give more info about my project but it is fairly standard so I'm not sure what information is relevant.</li>
  </ul>
  <hr />
  <h3>UPDATE</h3>
  <p>Thanks to Tagir's idea I've managed to find one of the culprits. This class adds 20 seconds to the compilation time:</p>
  <pre><code>import org.jooq.DSLContext;
  import org.jooq.Field;
  import static org.jooq.impl.DSL.field;
  import static org.jooq.impl.DSL.round;
  import static org.jooq.impl.DSL.sum;
  
  
  class Test {
    static Object fast(DSLContext sql) {
      Field&lt;Double&gt; a = field(&quot;a&quot;).cast(Double.class);
      return sql.select()
              .having(round(sum(a).cast(Double.class), 2).ne(0d));
    }
    static Object slow(DSLContext sql) {
      return sql.select()
              .having(round(sum(field(&quot;a&quot;).cast(Double.class)).cast(Double.class), 2).ne(0d));
    }
  }
  </code></pre>
  <p>If the <code>slow </code> method is commented out, the compilation time is back to normal.</p>