Skip to content

Instantly share code, notes, and snippets.

@girish3
Last active April 5, 2020 05:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save girish3/6da7e8ad6b95ec65ef2686309ab7467c to your computer and use it in GitHub Desktop.
Save girish3/6da7e8ad6b95ec65ef2686309ab7467c to your computer and use it in GitHub Desktop.
[[Deprecated] Android studio/Gradle performance tips] #android

[Deprecated] migrated to notion

Gradle tweaks

Open or create a file called gradle.properties in .gradle directory. Inside the file, add following

  • org.gradle.parallel=true: Allow you to build multiple modules in the same project at the same time
  • org.gradle.daemon=true will turn on daemon so that every time we build the application, it doesn’t need to rerun the entire Gradle application every time.

Memory Allocation tweaks

By default, Android Studio detects your installed RAM and configure the memory allocation automatically. However, the default value usually is too small to handle Android Studio. We can override it by opening it inside the Android Studio. Click Help > Edit Custom VM Options.

There are 4 config values you need to change:

  • -Xms1G: Specifying the initial size of the memory allocation pool for JVM. For PC with 8GB of RAM, start specifying with -Xms1G is a sweet spot.

  • -Xms2G: Specifying the maximum size of the memory allocation pool for JVM. For PC with 8GB of RAM, -Xmx2G is a good value to start.

  • -XX:MaxPermSize=1G: Specifying the permanent generation. This allocated memory holds compiled class pages. If it’s already full, then it triggers a full garbage collection to clean the old unreferenced classes. I would say start with -XX:MaxPermSize=1G for a PC with 8GB of RAM. Some people said it’s not necessary anymore in Java 8, but I do still configure it anyway.

  • -XX:ReservedCodeCacheSize=512m: Specifying the reserved code cache size. I don’t really understand what this config affects. But, still configure it anyway. In a PC with 8GB of RAM we can start with -XX:ReservedCodeCacheSize=512m.

Build gradle with profile report

./gradlew android:assembleDebug --profile

--profile flag will tell gradle to measure the time taken to execute each task and dump that data into HTML file. You can find that report under /projectDir/build/reports/profile directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment