97

I've noticed Android Studio (when running) uses greater than 100% CPU at all times, even when it appears there are no background processes that the IDE is running (indexing, etc). I might suspect this were something specific to my box, but some fellow developers are encountering this as well.

Often times the CPU usage is in the high 100s or mid 200s (see screenshots below). Has anyone encountered this as well? If so, are there any strategies or options within the IDE to correct this intensive use of system resources?

enter image description here

enter image description here

Shaun
  • 1,539
  • 1
  • 12
  • 11

12 Answers12

70

Thanks to Buzzrick (answered on this page, probably above my answer), he mentioned about VCS. Turning off all of the background operations of VCS seemed to have a HUGE impact toward the high cpu usage - it was 150% and now it's 20%, more or less.

I'm on OS X

Go to: Preferences > Version Control > Background. Now listed under 'Background Operations' are 6 options. I disabled the first three options which are:

Perform update on VCS in background, Perform commit to VCS in background, Perform checkout to VCS in background.

Miguel P.
  • 1,007
  • 7
  • 13
  • This worked great for me in Linux (Ubuntu) too. I just disabled all VCS background options and from hogging the CPU, now it's using less than 2% of it according to top. So many thanks! – Fran Marzoa Mar 02 '18 at 19:28
  • 3
    This was a MASSIVE improvement for me. Invalidate caches only did so much, but I would still regularly see well over 100% for AS and java (over 300% when building!), and now it's in the single digits at rest. I'm on AS 3.4.1, fyi. – pdub May 24 '19 at 15:43
  • I can't seem to find this "Background" menu. I perform a search in the Settings but it won't show, but when I do a Search All through the Shift keys I can see them, but clicking on them leads me nowhere. Might it be disabled? – John Ernest Guadalupe Jul 06 '19 at 03:56
  • There should be a 'Background' tab listed under 'Version Control' in settings. – Miguel P. Jul 06 '19 at 04:36
  • 3
    Miguel, if I wasn't married (and a guy) I would offer to have your love child. Thanks! – Jason Feb 13 '20 at 16:21
  • 1
    Before: %270, After: %2. A peaceful silence in my room ... – Mahmut K. Jun 20 '20 at 20:51
  • Google should mention about this setting in Official Devloper Documentation. Thanks man! – zackygaurav Oct 18 '20 at 07:33
  • disabling all VCS actions in BG works like a charm! Voila! CPU usage is dropped to <1% in idle state. almos 20-40% drop for me. testted for 24 hours and more! – sud007 Nov 29 '20 at 16:51
  • This works on Linux Mint too. Great stuff, thanks! – Raymond Sep 09 '21 at 03:57
  • This worked on Windows 10 Android Studio Chipmunk as well – Shoom Kloom Jun 06 '22 at 13:06
  • Not seeing these options anymore in Android Studio 2022.1.1. Invalidating caches did the trick though. – Snake Mar 24 '23 at 00:31
55

You can try the following options in the File Menu:

  1. File Menu -> Invalidate Caches / Restart... -> Invalidate and Restart
  2. Enable Power Save Mode by clicking on File -> Power Save Mode

Power Save mode only disable code insights and background tasks.

muneikh
  • 2,067
  • 5
  • 25
  • 59
  • 4
    I'm expiriencing the same issue with Android Studio, but not with IntelliJ IDEA 12.1.4. So it seems to be an Android Studio specific problem, not IntelliJ itself. The problem starts when I start the build process (using maven). – bergvandenp Nov 25 '13 at 17:30
  • So far this has helped on Windows - though I just tested it briefly, so I can't say I'm positive it will work in the long-run, and it also seems strange that without "Power Save" the IDE would take over the entire CPU... – Matt Jan 29 '14 at 19:04
  • 3
    Update: This helps, but it also seems to cripple some of the functionality of the IDE (like auto-complete, and some icons have disappeared, probably no realtime git support?) – Matt Jan 29 '14 at 20:34
  • 1
    With the recent version of Android Studio v5+, auto complete works in Power Save mode. – muneikh Apr 08 '14 at 03:42
  • 2
    This does make things better , but not really practical as it disables too many features I use. – idanakav May 26 '15 at 12:10
  • 1
    Power save mode is still available in Android Studio 3.1 and has been improved since earlier versions. – muneikh Jul 09 '18 at 13:18
34

You might consider going to File > Invalidate Caches / Restart Your cache might be kicking off something funky in the background

enter image description here

k.chao.0424
  • 1,191
  • 10
  • 11
14

I encountered a constant high cpu usage with no apparent reason. Invalidating cache did not work nor did the power save mode.

In my case there was a something wrong in the '.git' directory which was causing android studio to fail in an endless loop. Checking out the repo again fixed the problem.

My advice is to check the android studio logs for any hints to what is causing it to falter. You could also start it from terminal and check the Stdout/Stderr output.

odedfos
  • 4,491
  • 3
  • 30
  • 42
  • This was the case for me. I added an alias to the git config which made Android Studio unusable. – McP Nov 26 '15 at 16:37
  • 3
    Similar case for me. Committing changed files and pushing to the repo fixed it. – Simas Jul 01 '17 at 14:31
6

I switched on power save in Android Studio 1.0 it helped but this meant I opted out on so many features that Android Studio has to offer. Thus I sought to find a better solution, I happened to always have a dialog box pop up and ask me to increase my VM size. Apparently once I increased this, I am able to switch off power save and have my Android Studio work perfectly.

This is how to do so: On Mac OS go to /Applications/Android\ Studio.app/Contents/bin/studio.vmoptions (To open contents right click on Android Studio app > View contents) You will find the following variables

-Xms128m
-Xmx4096m
-XX:MaxPermSize=1024m
-XX:ReservedCodeCacheSize=200m
-XX:+UseCompressedOops

On Windows go to Environment Variables and find a System Variable called _JAVA_OPTIONS

Increase these figures accordingly.

  • Xmx specifies the maximum memory allocation pool for a Java Virtual Machine (JVM).
  • Xms specifies the initial memory allocation pool.

i.e Your JVM will be started with Xms amount of memory and will be able to use a maximum of Xmx amount of memory.

Kennedy Nyaga
  • 3,455
  • 1
  • 26
  • 25
4

I had exact same problem on Linux. Solved by increasing the memory size.

Started by looking at the top -p <android studio pid> -H which shows which threads are using most of CPU, to me there are three threads: 94232,94233,94234. Then I do a jstack <pid> to get the stack dump of android studio, and look for 0x17018 (=94232), it turns out to be "Gang worker#0 (Parallel CMD Threads)". All three of them. apparently JVM is too busy doing GC all the time.

Also opened jconsole against my android studio process and it shows GC time "20 minutes"!!! (at the bottom of memory tab)

Fix is to change the studio.vmoptions (or studio64.vmoptions in my case), to increase the -Xmx value from default 750m to 1500m. It is sufficient for me. if you have too much memory, set to 2g or 4g or 16g..

Shawn
  • 1,598
  • 1
  • 12
  • 19
  • Thanks for the hints on the existence of `jstack`. Being a first time user of this I obvisouly don't know how to use it properly, but I can see there's some VCS thread in BLOCKING state. I'm not sure if this is the root cause, but it seems to fit some of the other descriptions found here. – Stephan Henningsen Dec 19 '18 at 08:20
4

Interestingly, for me this seemed to be something to do with the version control integration.

I fixed this by re-loading my android studio project and when it asked about wiring up my CVS links (I don't recall the exact wording), I just said "Ignore". After that it ran smoothly without pulling CPU

Buzzrick
  • 823
  • 9
  • 21
3

I tried the following procedure and Android Studio on my Surface Pro 3 sped up by an insane amount:

  1. Reduce the amount and memory of the Android Virtual Devices you have.
  2. Invalidate Caches/Restart
  3. Go to Power Save Mode
  4. Close all unnecessary files that are opened.
  5. Reduce your VM Heap Size to around 256.
Henry Zhu
  • 2,488
  • 9
  • 43
  • 87
3

On Windows I reduced the studio64.exe process priority and set the process' affinity to half of the cores. Open Task Manager, click on Processes tab, right click on process studio64.exe and you'll see it in the menu.

Daniel Nuriyev
  • 635
  • 6
  • 10
1

In my case I have white-listed Android-Studio's folder in "Eset Smart Security" and the problem solved!

hope this helps!

Edit:

Disabling HIPS in Eset settings was also helpful in my situation!

Homayoon Ahmadi
  • 1,181
  • 1
  • 12
  • 24
1

You can check which part of Android Studio or which plugin is using a lot of CPU, with Android Studio -> Help -> Diagnostic Tools -> Activity Monitor

On Android Studio 2.3, this used to happen when the "Android Monitor" window was open (the window shows Logcat messages from devices and emulators), and then you press Ctrl+F (Cmd+F on the Mac) to reveal the 'Find' search bar inside this window.

It can also happen when you connect a Samsung phone to your computer via USB, which has Developer Mode enabled, because Samsung phones usually send out large amounts of debug text to Logcat every second, even if the Logcat window is closed.

So the solutions to prevent the 100% CPU usage are either:

  • Turn off the Find search bar, or hide the window completely. Or ...
  • Disconnect a Samsung phone which is sending out lots of debug messages. Or ...
  • Upgrade to Android Studio 3, where this bug doesn't happen. Or ...
  • If all else fails, just restart Android Studio
Mr-IDE
  • 7,051
  • 1
  • 53
  • 59
1

I've left this question open for awhile as coworkers and posters here have found value in various solutions over time. For myself, simply updating Android Studio solved the issue (after a number of months where none of the solutions herein worked for me).

Shaun
  • 1,539
  • 1
  • 12
  • 11