6

When Android Studio builds my project, it easily eats up all my 8 cores. I'd like to be able to fluently browse the internet while my app is compiling. Is there a way I can set Gradle's java processes to have a low priority (nice level > 10)?

That solution works perfectly for my gentoo system (with portage running on niceness 19 I can normally use my PC while it's compiling). Optimally, only Gradle's java should run at low priority, so Android Studio itself remains responsive. If that's not possible, maybe is it easier to limit Gradle's java VMs to use only 5-7 cores? It would probably result in longer build times though.


EDIT

I experimented with this manually for a bit. I ran a script in a loop that sets nice level 15 ("priority low" for the windows users) for all new java processes every second. Unfortunately, the system is still not very responsive. I see that during compilation my average load goes up to twenty where I have only 4 (logical) cores. This means that Gradle spawns way too many threads. Somewhere else I read that also these threads rarely yield, which may be the cause why lowering priority doesn't help.

So, updated question is: is it possible to limit the number of threads used by Gradle?

2

It seems like a known issue, there's an ongoing debate about this upstream: https://code.google.com/p/android/issues/detail?id=66696

They say the build should use a shared thread pool, the parameter to set its size is -Pandroid.threadPoolSize=<count> and should be available in Android Studio 2.3 beta 3.

| improve this answer | |
  • Can you summarise? – bertieb Mar 18 '17 at 19:27
  • 1
    @bertieb ok, edited the answer. I didn't test it yet as I'm still on Studio 2.2, but I'm watching the linked thread for more info. – quezak Mar 18 '17 at 19:58
0

Just create shortcut with follwing path:

cmd.exe /c start "Android Studio" /LOW "C:\Program Files\Android\Android Studio\bin\studio64.exe"

Or set priority every time in task manager, but I believe this approach is better : )

| improve this answer | |
  • 1
    Thanks for the suggestion, I've tried similar things with nice level on linux. While with this the gradle processes spawned by Studio will have lower priority, so will have Studio process itself -- so, while compiling, IDE's window may also be unresponsive. After experimenting it seems that this doesn't solve the problem anyway, see the question edit. – quezak Sep 16 '16 at 9:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.