🚀 The Ultimate Gradle Optimization on M4

How I optimized my Android build time to be faster on M4

Hardware: Apple Silicon architecture (Mac Mini M4 with 16GB RAM):

  • ARM64 optimization
  • Unified memory architecture
  • I/O speeds
  • Perfect for parallel workloads

Configuration: gradle.properties

org.gradle.jvmargs=-Xmx3072m -XX:MaxMetaspaceSize=1g -XX:+UseG1GC -XX:+AlwaysPreTouch -XX:+UseStringDeduplication
org.gradle.daemon=true
org.gradle.parallel=true
org.gradle.caching=true
org.gradle.workers.max=8
org.gradle.caching.debug=false
org.gradle.configuration-cache=true

What each parameter does:

Parameter Purpose
-Xmx3072m 3GB RAM for Gradle (sweet spot for M4)
-XX:+UseG1GC Low-latency garbage collector
-XX:+AlwaysPreTouch Pre-heats memory for faster access
-XX:+UseStringDeduplication Eliminates duplicate strings
org.gradle.parallel=true Uses all M4 cores
org.gradle.configuration-cache=true caches the configuration phase (important for incremental builds)

Results

Configuration Build Time Improvement
Default config ~3 minutes Baseline
Basic memory tweaks 3.045s 98% faster
Adding Parallel GC 5.294s Wait, worse!
Sweet spot found 1.222s 99.3% faster
With warm caches 0.503s 99.7% faster
Incremental build 0.407s 99.8% FASTER

Comments

Popular posts from this blog