$30 off During Our Annual Pro Sale. View Details »

Performance tweaks for Android Studio and Gradle by Samuel Dionne

Performance tweaks for Android Studio and Gradle by Samuel Dionne

Android Studio is an awesome tool for Android development, but it may be sluggish at times. We’ll explore some of the ways you can tweak it to make it faster. AS is not the only culprit when it comes to performance. Gradle builds are sometimes, nay, always slow but there are some parameters we can use to improve its performance. When everything else fails, raw power does it.

https://gdgmontreal.com/2020/02/11/february-2nd-meetup/

studio64.vmoptions
-Xms3g
-Xmx3g
-XX:NewRatio=3
-XX:ReservedCodeCacheSize=480m
-XX:MetaspaceSize=512m
-Xss16m
-XX:+UseCompressedOops
-Dfile.encoding=UTF
-Dawt.useSystemAAFontSettings=on
-Dsun.java2d.noddraw=false
-XX:+UseConcMarkSweepGC
-XX:SoftRefLRUPolicyMSPerMB=50
-server

gradle.properties
android.enableJetifier=true
android.useAndroidX=true
org.gradle.jvmargs=-Xmx2560M -Dkotlin.daemon.jvm.options="-Xmx2560M" -Dfile.encoding=UTF-8
org.gradle.daemon=true
org.gradle.parallel=true
org.gradle.caching=true
kapt.incremental.apt=true
kapt.use.worker.api=true
kapt.include.compile.classpath=false

GDG Montreal

February 26, 2020
Tweet

More Decks by GDG Montreal

Other Decks in Technology

Transcript

  1. Performance tweaks
    for AS and Gradle
    12 + 1 tips to make your life better

    View Slide

  2. Samuel Dionne
    Transit
    Android development for
    10 years
    Started on Eclipse
    AS + Gradle is still
    painful

    View Slide

  3. 7 Gradle tips
    5 Android Studio tips

    View Slide

  4. 7 Gradle tips
    5 Android Studio tips

    View Slide

  5. 1. Disable Plugins
    File > Settings > Plugins

    View Slide

  6. 2. Custom VM Options
    Help > Edit Custom VM Options

    View Slide

  7. Here is the content of my studio64.vmoptions
    # custom Android Studio VM options, see https://developer.android.com/studio/intro/studio-config.html
    -Xms3g
    -Xmx3g
    -XX:NewRatio=3
    -XX:ReservedCodeCacheSize=480m
    -XX:MetaspaceSize=512m
    -Xss16m
    -XX:+UseCompressedOops
    -Dfile.encoding=UTF
    -Dawt.useSystemAAFontSettings=on
    -Dsun.java2d.noddraw=false
    -XX:+UseConcMarkSweepGC
    -XX:SoftRefLRUPolicyMSPerMB=50
    -server

    View Slide

  8. 3. No dynamic version
    in gradle dependencies

    View Slide

  9. 4. Experiment settings
    File > Settings > Experimental

    View Slide

  10. 5. Memory indicator
    File > Settings > Appearance

    View Slide

  11. 7 Gradle tips
    5 Android Studio tips

    View Slide

  12. 1. Disable PNG
    Cruncher
    buildTypes.debug.crunchPngs

    View Slide

  13. 1. Disable PNG
    Cruncher
    File > Settings > Plugins
    Better Yet!
    Convert all images to WebP*

    View Slide

  14. 2. Disable Crashlytics
    Build Id
    ext.alwaysUpdateBuildId

    View Slide

  15. 2. Disable Crashlytics
    BuildId
    build.gradle
    Better Yet!
    Disable Crashlytics completely
    ext.enableCrashlytics

    View Slide

  16. 3. Enable daemon
    org.gradle.daemon

    View Slide

  17. 4. Parallel build
    org.gradle.parallel

    View Slide

  18. 5. Caching*
    org.gradle.caching

    View Slide

  19. 6. Memory params
    org.gradle.jvmargs

    View Slide

  20. Here is the content of my gradle.properties
    android.enableJetifier=true
    android.useAndroidX=true
    org.gradle.jvmargs=-Xmx2560M -Dkotlin.daemon.jvm.options="-Xmx2560M" -Dfile.encoding=UTF-8
    org.gradle.daemon=true
    org.gradle.parallel=true
    org.gradle.caching=true
    kapt.incremental.apt=true
    kapt.use.worker.api=true
    kapt.include.compile.classpath=false

    View Slide

  21. 7. Offline mode
    File > Settings > Build > Gradle

    View Slide

  22. 5 Android Studio tips
    7 Gradle tips

    View Slide

  23. 5 Android Studio tips
    7 Gradle tips
    Please make it even
    FASTER

    View Slide

  24. 5 Android Studio tips
    7 Gradle tips 50k Mac Pro

    View Slide

  25. 5 Android Studio tips
    7 Gradle tips Steal CPU and Memory
    50k Mac Pro

    View Slide

  26. 5 Android Studio tips
    7 Gradle tips
    50k Mac Pro
    Steal CPU and Memory Rent a Big Server

    View Slide

  27. 1. Copy our local files
    to the server

    View Slide

  28. 1. Copy our local files
    to the server
    2. Run gradle build on
    the server

    View Slide

  29. 1. Copy our local files
    to the server
    7. Offline mode
    File > Settings > Build > Gradle
    3. Copy the results
    files locally

    View Slide

  30. Gradle plugin Mirakle
    github.com/Instamotor-Labs/mirakle

    View Slide

  31. - 3x faster incremental build
    - 5x faster full build
    - Shared C++ cache
    - Shared Gradle build cache
    (coming soon)
    - 6 person team == lot of minutes
    saved

    View Slide

  32. Thank you for listening
    Questions?

    View Slide