Android Studio is slow (how to speed up)?

kha picture kha · Jun 13, 2015 · Viewed 280.4k times · Source

I recently upgraded from Eclipse to Android Studio and I'm not really liking the experience. I'm comparing them both on a Windows 7 64 bit ultimate with 16GB of ram and Intel i7 4770 running NVidia Geforce 780 with the latest NVidia drivers if it matters and I'm running the latest JDK and the latest Android Studio.

The Android Studio is very slow in building the project which I can live with but it's also extremely resource intensive and sometimes slows down the PC to a crawl.

Whenever I'm building or running anything in AS, my PC seems to become extremely sluggish. It also causes flickering of screen and occasionally blanking my second monitor if I click on "Gradle build running" spinner which I find very odd. The RAM usage also shoots up to ~3GB which I find excessive for doing nothing (this is when it's idle after a few builds).

In addition, the panels at the bottom of AS keep jumping around which is a horrible user experience (moves from Android to Messages to Version Control or anything else on an ad-hoc basis depending on what's happening which is very, very annoying).

What I would like to know is basically:

1) How do I make Android Studio run better? I may be doing something wrong or missing some updates that I'm not aware of and I'm sure others have also noticed these behaviors and have found some solutions to it.

2) How do I "pin" the bottom panels so that they don't jump around and instead, let me, the user, navigate to them when I wish to instead of automatically switching them?

Many thanks and my apologies again if it's not the correct place for these questions.

Edit 1 Some more comments:

  • I'm using the latest stable build as of today. The build is Android Studio 1.2.2 Build # AI-141.1980579, Build on June 3, 2015
  • The behavior happens when using either Java 7 or 8. It doesn't appear to be related to the version of Java.
  • I am not using Presentation Mode. Just the vanilla view.
  • Doing the changes to the build configuration (thanks to @Blackbelt and his answer) appears to have helped with the build but the other problems with sluggishness and general user experience remain.

Answer

Blackbelt picture Blackbelt · Jun 13, 2015

to sum it up

1) in AndroidStudio's settings > compile enable checkbox named Compile independent modules in parallel.

2) Under Help> Edit Custom VM Options I have:

-Xms1024m 
-Xmx4096m # <------ increase this to most of your RAM 
-XX:MaxPermSize=1024m 
-XX:ReservedCodeCacheSize=440m 
-XX:+UseCompressedOops 
-XX:-HeapDumpOnOutOfMemoryError 
-Dfile.encoding=UTF-8

P.S. - Some people say Note, instead of VM options, it's better to combine can be overriden by combining those lines into one line single command in gradle.properties, like this :

org.gradle.jvmargs=-Xms1024m -Xmx4096m ......

3) I have an old dual core with 4GB ram, running ubuntu. Qs command line option I have only --offline (which specifies that the build should operate without accessing network resources). I also enabled the remaining checkboxes and now it's running ok:

  • Make project automatically

  • Use in-process building Configure on demand

  • Check the AndroidStudio's settings, under compile that the checkbox Compile independent modules in parallel is enabled.

Under Vmoptions I have

-Xmx2048m -XX:MaxPermSize=1024

I have an old dual core with 4GB ram, running ubuntu. Qs commandline option I have only --offline , which specifies that the build should operate without accessing network resources. I enabled also the remaining checkboxes:

  1. Make project automatically
  2. Use in-process building
  3. Configure on demand

    and it is running ok

Edit

It is possible to provide additional options through studio.vmoptions located at (just replace X.X with version):

  • Windows: go to %USERPROFILE%\.AndroidStudioX.X\studio.exe.vmoptions (or studio64.exe.vmoptions)

  • Mac: ~/Library/Preferences/.AndroidStudioX.X/studio.vmoptions

  • Linux: ~/.AndroidStudioX.X/studio.vmoptions (and/or studio64.vmoptions)

Increasing the value of -Xmx should help a lot. E.g

-Xms1024m
-Xmx4096m
-XX:MaxPermSize=1024m
-XX:ReservedCodeCacheSize=256m
-XX:+UseCompressedOops

will assign 4G as max heap, with initial value of 1G

Edit:

On windows the defaults are stored into C:\Program Files\Android\Android Studio\bin\*.vmoptions. The IDE allows you to tweak those values through Help->Edit Custom VM options (thanks to @Code-Read for pointing it out).

EDIT 2:

Android studio 3.5 makes easier to change same of those values. Just go to:

Preferences > Appearance & Behavior > System Settings > Memory Settings