in the last few months upgrading Kotlin with every...
# announcements
j
in the last few months upgrading Kotlin with every version, our build times became slower and slower builds used to take around 2 minutes max, now we're lucky if we get a
mvn clean package
to run in 20-24 minutes even with the incremental option on, that first
mvn package
or running it from IntelliJ takes almost 30 minutes not sure if Kotlin compile times became much slower or if our code-base became exponentially bigger we have about 2k lines of Java code and 114k lines of Kotlin code, so not that enormous any suggestions on how to make it faster?
Copy code
<plugin>
                <artifactId>kotlin-maven-plugin</artifactId>
                <groupId>org.jetbrains.kotlin</groupId>
                <version>${kotlin.version}</version>
                <configuration>
                    <jvmTarget>${java.version}</jvmTarget>
                    <compilerPlugins>
                        <plugin>jpa</plugin>
                    </compilerPlugins>
                    <pluginOptions>
                        <option>jpa:annotation=javax.persistence.MappedSuperclass</option>
                    </pluginOptions>
                </configuration>
                <executions>
                    <execution>
                        <id>compile</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                        <configuration>
                            <sourceDirs>
                                <source>src/main/java</source>
                                <source>src/main/kotlin</source>
                                <source>src/main/resources</source>
                            </sourceDirs>
                        </configuration>
                    </execution>
                    <execution>
                        <id>test-compile</id>
                        <phase>process-test-sources</phase>
                        <goals>
                            <goal>test-compile</goal>
                        </goals>
                        <configuration>
                            <sourceDirs>
                                <source>src/test/java</source>
                                <source>src/test/kotlin</source>
                                <source>src/test/resources</source>
                            </sourceDirs>
                        </configuration>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>org.jetbrains.kotlin</groupId>
                        <artifactId>kotlin-maven-noarg</artifactId>
                        <version>${kotlin.version}</version>
                    </dependency>
                </dependencies>
            </plugin>
d
At first try to increase heap size for a maven process. export MAVEN_OPTS="-Xmx4096m" Is it acceptable to share your project's source files? (you can attach the files here visible for Kotlin team only) It would be very helpful, but if you can't do that we need at least a performance snapshot of compiler process. To make the snapshot you need to download a yourkit agent (https://github.com/gilt/sbt-yourkit/tree/master/src/main/resources/yjp-2016.02/bin) suitable for your OS and modify the gradle.properties as following:
Copy code
export MAVEN_OPTS="-agentpath:/path/to/yourkit/agent.so=sampling,onexit=snapshot,delay=0,dir=/path/to/snapshots -Xmx4096m"
YouTrack issue with resulting snapshot is very welcome at https://youtrack.jetbrains.com/issues/KT
j
i've tried -Xmx512m before and it hardly made a dent, but at 4096, it made a significant dent
Copy code
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 03:35 min
[INFO] Finished at: 2018-08-27T23:11:06+02:00
[INFO] ------------------------------------------------------------------------
down from 25-30min to less than 4min, that's awesome, thanks for the help Denis! i'll get back to the profiler part to see where it's taking time, screenshotting this and logging as something to get back to as soon as all the high priority stuff are out of the way
at
8192m
build time is down to 02:56, so cuts a further ±40 seconds is there a way to specify that parameter directly in the maven compiler plugin so that intellij can pick up on it? I've added it to the
maxmem
config option to see if if it makes a difference in IntelliJ:
Copy code
<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <forceJavacCompilerUse>true</forceJavacCompilerUse>
                    <fork>true</fork>
                    <meminitial>512m</meminitial>
                    <maxmem>8192m</maxmem>
                </configuration>
                <executions>
                    <execution>
                        <id>compile</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>testCompile</id>
                        <phase>test-compile</phase>
                        <goals>
                            <goal>testCompile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
Played around in intellij, enabled 4 threads under the maven settings, set the parallel flag under compiler and set the heap size to 4096, under the Kotlin Compiler options, i switched it to Java 1.8 (not sure why 1.6 is the default there). Build time is now 2 min 55 seconds compared to where it was still doing close to 30 minutes yesterday (yes, i did a
mvn clean
before telling IntelliJ to do the run / debug). Activity monitor shows that the Java process peaks at 3GB of memory, so more memory probably won't speed it up any further.