Skip to content

Commit

Permalink
chore(labs): improve build and test speed
Browse files Browse the repository at this point in the history
This changeset optimizes the Guava build significantly by enabling
parallel build and test features supported by Maven. With these
flags enabled, only a few tests exhibit flaky behavior; applying a
sensible count of test retries (3) solves the problem.

As a result, the testsuite can now be executed often, because it
takes about 2 minutes to run. Building is also much faster. After
benchmarking different configurations, 2-threads-per-core and
2-test-forks-per-core seems optimal:

```
[INFO] Guava Maven Parent ..................... SUCCESS [  0.121 s]
[INFO] Guava: Google Core Libraries for Java .. SUCCESS [  9.681 s]
[INFO] Guava BOM .............................. SUCCESS [  0.120 s]
[INFO] Guava Testing Library .................. SUCCESS [ 47.883 s]
[INFO] Guava Unit Tests ....................... SUCCESS [01:57 min]  <--
[INFO] Guava GWT compatible libs .............. SUCCESS [  6.909 s]
```

When built and executed serially:
```
[INFO] Guava Maven Parent ..................... SUCCESS [  0.129 s]
[INFO] Guava: Google Core Libraries for Java .. SUCCESS [ 15.653 s]
[INFO] Guava BOM .............................. SUCCESS [  0.064 s]
[INFO] Guava Testing Library .................. SUCCESS [01:26 min]
[INFO] Guava Unit Tests ....................... SUCCESS [06:26 min] <--
[INFO] Guava GWT compatible libs .............. SUCCESS [ 11.092 s]
```

Benchmark hardware:
- Apple M2 Max, 96GB RAM
- macOS Sonoma 14.3.1
- GraalVM CE JVM 21.0.2

```
openjdk version "21.0.2" 2024-01-16
OpenJDK Runtime Environment GraalVM CE 21.0.2+13.1 (build 21.0.2+13-jvmci-23.1-b30)
OpenJDK 64-Bit Server VM GraalVM CE 21.0.2+13.1 (build 21.0.2+13-jvmci-23.1-b30, mixed mode, sharing)
```

- chore: enable parallel build
- chore: enable parallel test execution
- chore: enable parallel gc for maven
- chore: tune tiered compilation for maven
- chore: tune thread count for maven
- fix: enable test retries (max = 3) for parallel-flaky tests

Signed-off-by: Sam Gammon <[email protected]>
  • Loading branch information
sgammon committed Mar 10, 2024
1 parent 2d6a7e4 commit d6c6548
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions .mvn/jvm.config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-XX:-TieredCompilation -XX:TieredStopAtLevel=1 -XX:+UseParallelGC -Djava.awt.headless=true
2 changes: 2 additions & 0 deletions .mvn/maven.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-T2C
--strict-checksums
9 changes: 8 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
<description>Parent for guava artifacts</description>
<url>https://github.com/google/guava</url>
<properties>
<!-- Enable parallel test execution -->
<parallel>all</parallel>
<perCoreThreadCount>false</perCoreThreadCount>
<threadCount>48</threadCount>
<!-- Override this with -Dtest.include="**/SomeTest.java" on the CLI -->
<test.include>%regex[.*.class]</test.include>
<truth.version>1.4.2</truth.version>
Expand All @@ -33,6 +37,7 @@
<otherVariant.jvmEnvironmentVariantName>android</otherVariant.jvmEnvironmentVariantName>
<publishing.repository.snapshots>https://oss.sonatype.org/content/repositories/snapshots/</publishing.repository.snapshots>
<publishing.repository.releases>https://oss.sonatype.org/service/local/staging/deploy/maven2/</publishing.repository.releases>
<surefire.rerunFailingTestsCount>3</surefire.rerunFailingTestsCount>
</properties>
<issueManagement>
<system>GitHub Issues</system>
Expand Down Expand Up @@ -232,7 +237,7 @@
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.7.2</version>
<version>3.2.5</version>
<configuration>
<includes>
<include>${test.include}</include>
Expand All @@ -251,6 +256,8 @@
<!-- Set max heap for tests. -->
<!-- Catch dependencies on the default locale by setting it to hi-IN. -->
<argLine>-Xmx1536M -Duser.language=hi -Duser.country=IN ${test.add.opens}</argLine>
<reuseForks>true</reuseForks>
<forkCount>2C</forkCount>
</configuration>
</plugin>
<plugin>
Expand Down

0 comments on commit d6c6548

Please sign in to comment.