📜 ⬆️ ⬇️

Comfortable work with Android Studio


Good day to all!


How productive is Android Studio? Do you think it works fast on your PC or Mac? Or, sometimes, encounter lags or a long build? And on large projects?


In any case, we all want to get maximum performance from hardware and software. Therefore, I have prepared a list of points and tips for beginners and experienced developers who will help you to work comfortably with large projects or simply to increase productivity. You will also understand if your equipment needs an upgrade.


Users of other popular IDEs may also find something useful for themselves.


Motivation


Android Studio was awkward during the transition from Eclipse. And even then I started looking for ways to optimize the work of this IDE. However, the majority of colleagues related to this "nothing". Works. Not always fast. And ok.


But now I have been working for another company for a year. The climate is different, developers read reports on various technologies. At one of these reports, it seemed to me that the topic of this article may be relevant. Especially in the framework of projects of increased technical complexity.


After talking with colleagues and familiar developers, it became clear to me that not even every “pro” understands the nuances of the hardware, OS and IDE. Because here I tried to collect a complete educational program based on my own experience.


DISCLAIMER! All the models and brands mentioned in the article are not advertising!


Iron


Here is what is said about hardware on the official website of Android Studio in the System requirements column (not counting disk space):


3 GB RAM minimum, 8 GB RAM recommended; plus 1 GB for the Android Emulator 1280x800 minimum screen resolution 

This is enough for the studio to simply start and work. About any performance and comfort there is no question.


In this chapter, I will talk about what hardware is desirable to have for comfortable work with large projects and what can become a bottleneck in your system.


Here, 5 parameters are most critical for us:



Since I more often worked on configurations based on Intel products, then we will discuss them later. However, if you have AMD, just read the corrections for similar “red” technologies for yourself. The only minus with which I came across on AMD, was already described on Habré .


A couple of words about Mac


There is an opinion that Mac is the best development machine. More often say so about the MacBook Pro.


Personally, I think this is a myth. With the advent of technology NVMe Mac lost its "magic". So today, even among laptops, Mac is not the leader in price-performance-performance ratio. Especially in the context of development for Android Studio.


Otherwise, for a comfortable development it makes sense MacBook Pro 2015 or 2016 not with a U-processor. Read about other features and service below.


CPU


By processor performance, it is obvious and understandable. The higher it is, the better. The only thing that needs to be noted is that if there is a sufficiently fast drive, a weak processor will become a bottleneck in your system. Especially critical in the case of NVMe-drive. Often, when working with it, the emphasis goes precisely to the power of the CPU.


With threads, things are a little more complicated. I read that users reduce the priority of the studio and its subprocesses so that the OS "does not hang" during the build. The reason here is one- 1-2 hardware threads. This is not only for the IDE, but also for the modern OS. The only "but" - in my practice, there were situations when dual-core U-processors with Hyper Threading (that is, 2 cores to 4 threads) normally worked with relatively small projects, but the above-mentioned problems started on large ones.


Of course, the presence of hardware virtualization is required.


Therefore, I recommend looking towards the Sky i5 HQ Skylake with 4+ streams and more powerful.


RAM


Regarding the standards, DDR3 and higher. Here, I think, it is clear.


If there is an opportunity to work in 2 or 4-channel mode and you are not active, I strongly recommend using it, as you can get a significant increase in responsiveness of IDE. This feature is activated either in the BIOS \ UEFI settings, or by installing additional RAM modules (if you still have one module).


What volume is needed? For small (really small) projects, 4GB is enough. On larger projects, the studio is able to quickly take up 4GB of memory and more. Add here an emulator for HAXM (say 2 GB) and take into account that the modern OS (with the exception of some Linux distributions) takes up about 2 GB in memory, and now it turns out that 8GB is already “just right”.


This does not include, for example, Slack (which takes an average of about 500 MB in memory) and Chrome (where the bill goes to gigabytes).


In general, with 8GB of RAM, you can quickly and comfortably work; a fast drive and swap \ swap file save you. But it is worth thinking about the upgrade.


Therefore, the company buys new ones, or provides an upgrade of current working machines with 12GB of RAM or more.


SSD


The disk subsystem is the most frequent bottleneck, so it is necessary to pay attention to it first.


Working with Android Studio on HDD in 2018 is comparable to anguish - the larger the project, the more friezes you are provided for. Therefore, obviously, use only SSD.


As mentioned above, there are two critical parameters here:



The higher they are, the more responsive the studio will be, and the faster it will load and assemble.


I draw your attention to the fact that there is no talk of linear read / write speeds — for a studio, this is not critical. Therefore, when choosing a drive, you need to look not at its read / write speed on the manufacturer or store website, but on the number of IOPS (the more, the better).


Needless to say, there is no talk of Mac, since there the drive either has its own standard or is simply soldered on the board. Replacement is possible, perhaps, for a larger volume. High-speed performance here is unlikely to succeed.


Nvme


If your motherboard supports NVMe technology, then it is better to use a drive with its support. It allows you to get speeds comparable to SSD on Mac and above.


In the presence of high-speed storage, the emphasis goes to the PCIe bus and the power of your CPU. Therefore, if, for example, your motherboard supports output to a PCIe 2.0x4 \ 3.0x2 drive or you do not have a very powerful CPU, you should not buy a very expensive drive. Look at the capabilities of your system and the thickness of your wallet.


SATA3


Yes, SATA3 is very much alive. And you can quickly work at the studio.


In this segment, high-speed drives are more accessible, so it makes sense to immediately look at the top solutions of 120 GB or higher.


Intel optane


I did not have to use Android Studio on a machine with this drive (if you can call it that). If someone has experience, write in the comments.


GPU


There is not much to say.
If you write the usual user applications, for the studio itself and the emulator, something like the Intel HD 500 Series is enough for the eyes.


If you develop games or this is your personal machine, then discrete graphics make sense. How-see your needs.


Cooling system and throttling


This is not about upgrades, but about maintenance.


Most of us know such a thing as throttling . Its implementation is used to protect against overheating.


Of course, throttling leads to a decrease in performance. Not always noticeable. In some cases, the Turbo Boost operation is reduced to the minimum values; in others, the maximum processor frequencies fall. The reason is not enough efficient operation of the cooling system. It is also important to understand that most stress tests (like AIDA) diagnose Turbo Boost’s standard operation as throttling.


In the case of desktop PCs, everything has been online for a long time. In the case of mobile systems based on heat pipes, a lot of conflicting information. This includes most laptops, nettops, MacBooks and iMacs. Further, it will be about them.


On modern powerful mobile CPUs of 80-90 degrees on a chip under load, this is the norm. At the same time, SOC with these CPUs have an open-crystal design, from which the heat transfer area is small. All this heat is given away. here is this laughing stock similar design with a small closed fluid circuit.


Modern mobile cooling system


You need to understand that such cooling systems are under heavy loads and need more frequent maintenance. Especially in the case of laptops and MacBooks, when transported from vibrations, the layer of dried thermal paste breaks down faster. And late service is fraught with not only a loss of performance, but also a leakage of heat pipes and "heaps" of crystals.


The service consists in replacing the thermal paste and cleaning the radiator every six months or a year after the end of the warranty period. In any case, we are doing so.


Because of the small area of ​​the crystal, it makes sense to use dielectric thermal grease with high thermal conductivity (this costs around 800-1000 r per gram). Never use liquid metal! Otherwise, you probably will not be able to separate the crystal from the plate!


If you do not have enough skills for this procedure, it is better to contact the service.


Hardware settings


This chapter deals with the functions and settings of the equipment. Much, most likely, you already know.


Intel Hyper Threading


This is Intel technology, which divides the hardware kernel stream into two "virtual" ones. Thanks to it, the system sees the 4-core processor as an 8-core processor. This approach allows efficient utilization of processor power. AMD has a similar technology.


I often come across the fact that many developers have disabled this feature and they don’t know about it at all. However, its inclusion can increase studio responsiveness and build performance. In some cases, 10-15%.


It is enabled in the BIOS \ UEFI settings of your motherboard or laptop. The item is called the same or similar way. If you still did not know about this technology, then it makes sense to check its availability and enable it if this has not been done.


Intel Turbo Boost


Another well-known technology. In fact, it is an automatic short-term overclocking of the CPU and gives a significant increase in the assembly. And, at the same time, it tends to heat up mobile processors to temperatures not far from Tjunction .


Therefore, if this technology has previously been disabled, it is advisable to check the condition of the cooling system before switching on and, possibly, to perform its maintenance, as described in the previous chapter.


It can be included in the BIOS \ UEFI, as well as in the OS settings.


Intel Rapid Storage


Support for this motherboard technology is highly recommended. More details can be read here .


I can only recommend timely updating the drivers for this technology to the latest version from the official site of Intel. Even if the manufacturer of your laptop supplies you with older drivers.


In my particular case, the update from the driver version from the manufacturer to the current one, increased the linear recording speed by about 30%, and arbitrary - by 15%.


How to install and update IRST drivers on Linux - I do not know (and in general, is it possible?). If anyone knows, write in the comments, I’m happy to add an article.


SSD Secure Erase


The performance of inexpensive SSD models may fall over time. This does not always happen due to the “degradation” of the drive. Perhaps your TRIM model is not very efficiently implemented.


Secure Erase will force the controller to mark all memory cells empty, which, theoretically, should return the SSD performance to the factory state. And, also, erase all your data! Be careful, make backups!


To carry out the procedure, you can use a proprietary utility from the manufacturer. In case your disk is a system drive, then you will need a flash drive, which the utility will make bootable. Follow the instructions below.


At one stage, it may be necessary to reconnect the drive during operation. Therefore, in the case of M.2, the presence of an adapter is very desirable.


The use of third-party utilities for this operation is highly recommended.


However, if your SSD is significantly lost in speed in less than a year, it is better to change the drive for another model.


Hardware virtualization


This technology is necessary for fast operation of the x86-emulator. If it is disabled for you, enable it in the BIOS \ UEFI settings. Different vendors may have different settings names.


Yes, we all know about Genymotion and BlueStacks, which do very well without hardware virtualization. However, in the images of these emulators, some or many implementations of the Android API are greatly modified in order to increase speed. This can provoke behavior that you will never see on a real device. Or when debugging you can miss a couple of bugs. Therefore, the availability of working and smart AVD is highly desirable.


OS and Third-Party Software


In this chapter, we will discuss the possible configuration of the OS and the installation of third-party software to increase performance.


Indexing


Here we will talk about searching for Windows and Spotlight on Mac OS. These mechanisms can take up to 15% of the CPU capacity at build because they are trying to index everything that is generated in / build.


Of course, from the indexation it is necessary to exclude all the directories with which the studio works:



Antivirus


I know that not everyone in the development environment decided to use antivirus. But many use it. Including, sometimes, on Linux and Mac OS. And its use is completely justified.


Even if you have Windows 10 and do not have antivirus, Windows Defender performs its functions.


When building an antivirus can take a very significant share of the CPU. Therefore, all the directories listed in the "Indexing" column should be added to the antivirus exceptions. Also, in exceptions it makes sense to add the names of the processes of the studio itself and the JetBrains JVM.


Depending on the implementation of the anti-virus, the CPU consumption for them during the assembly will decrease significantly, or it will generally cease to consume CPU power. And the assembly time itself will noticeably decrease.


Disk or home directory encryption


These functions are present on all popular operating systems or are implemented by third-party software. Of course, the work of the studio in the encrypted file space may require more CPU power. How much depends on the implementation of encryption. Therefore, it is recommended to disable such functions either completely or, if possible, for the directories listed in the "Indexing" column.


Does TRIM work?


TRIM can be implemented both in hardware and in software. In the latter case, the obligation to call TRIM falls on the OS. And, for various reasons, a periodic call can be disconnected, which leads to a drop in the speed of the drive.


You can check the operation and resume calls to TRIM using specialized utilities. It is recommended to use the utility from the manufacturer of the drive.


Ramdisk


What is RAMDisk most have long known. But how effective is it in working with the studio?


From my own experience I will say not very much. Unless you transfer to the RAMDisk the project itself, the SDK, the studio, and so on. If you have enough RAM ...


With a simple transfer of a project weighing more than 500 mb (the figure is specified with a build cache), I could not achieve a gain of more than 15%. Most likely, calls to SDK and system API are braked. As a result, such an increase is quite expensive.


The following method is much more efficient and less expensive.


Caching requests to the drive


Something similar is implemented in Mac OS. However, in comparison with the technologies listed below, it is not so effective.


Unfortunately, I know only two implementations, and both are tightly tied to manufacturers' products. It's about Samsung RAPID and PlexTurbo .


Both technologies work according to similar principles (I describe it as I understand it myself):



The only difference is that RAPID uses the free balance of RAM as cache. Less residue — less cache size, less acceleration. PlexTurbo allows you to limit the maximum cache size and load it from the hard disk at system startup.


In the case of use on SATA 3, you can get a gain of up to 50%. When using NVMe-drive, less, but, often, also significant.


At the moment I have a Samsung 860 EVO SATA 3 in my work. Under the benchmark spoiler with i7 6700HQ and disabled Turbo Boost.


860 EVO before enabling RAPID and two runs after

RAPID off



First run



Second run



You can clearly see how the system starts caching data on the first run. The final result is significantly higher than the SATA 3 performance. However, the efficiency of this technology depends more on the CPU power. What is clearly seen when you turn on Turbo Boost.


860 EVO + RAPID + Turbo Boost


Synthetics is, of course, good. But this all works when reading / writing duplicate small files. And this is the most frequent operation when running Android Studio.


I now have a total project with a cache weighing more than 700 MB, consisting of 10 modules. One of the modules is a custom kapt based code generator with very heavy logic. Two NDK modules, one of which refers to a Boost along an external path. The rest is tons of Kotlin code.


If we compare the time for a complete rebuild of this project, the results are as follows:



In less lengthy processes, growth in the studio is noticeable immediately.


As a result, we can recommend these technologies and drives as a good way to improve performance. There were no complaints about stability.


Android Studio


Many of these tips are taken from here and supplemented with my comments. The rest is the result of my research and experience.


Updates


Advice though banal, but always relevant. If you are not legacy-project, then, if possible, try to keep the version of the studio and related components (such as Gradle, Android Plugin, Kotlin Plugin) up to date. Google and JetBrains do a lot of work in terms of optimizing the speed and build in new versions.


Sometimes, of course, embarrassment happens when new versions stop behaving predictably and provoke errors. Therefore, we have a regulation on how to act in such situations.


In some cases, you need to run File-> invalidate caches and restart after a rollback. If you update the studio itself, it’s better to backup the studio directory and settings directory. This is true if your project contains any crutches , .


Project structure


, , API, library-. . , , .


, . , .


Instant Run


. " ". . -.


, , . . , - , Instant Run.


Build, Execution, Deployment -> Instant Run Enable Instant Run.


Attach to Process


. , ( ) . .


, - Attach debugger to Android process.


Gradle build configs


, buildConfig flavour , release- (, crashlytics, annotation- gradle-)- debug . - , , .


, buildConfig, PNG crunching, - debug-. png . :


 android { buildTypes { myConfig { crunchPngs false } } } //   android plugin android{ aaptOptions { cruncherEnabled false } } 

WebP


minimum api level 18, WebP. , . . , - .



(, app-), Compile independent modules in parallel Settings->Build, Execution, Deployment -> Compiler. CPU . - heap size , , .


gradle.properties


org.gradle.parallel=true


Gradle daemon


- , .


jvm gradle . . - . gradle.properties


org.gradle.daemon=true


Offline-


Gradle web- , . . , - .


Build, Execution, Deployment -> Gradle Offline work.


heap size Android Studio IDEA


. xmx1280m ( , RAM ). GC , , .


heap size , Gradle.


Gradle gradle.properties


org.gradle.jvmargs=-Xms1024m -Xmx4096m


1 4 . , .


Android Studio IDEA Help -> Edit Custom VM Options JVM- .


JVM , - . java -X .



, IDE. - . . .


- . Settings -> Plugins , , . , - .


Inspections


Settings -> Editor -> Inspections IDE. .


, . - , .


Power Save mode


File. (, , Spell Checking ..). . , , VS Code.


, .


Settings Repository


, . . .


codestyle- Git, copyright , codestyle .


, , .idea , - .


AVD


AVD . 3 , ( x86-).


, x86- Pie AVD . . , .


, HAXM 2 RAM .


, AVD CPU - , . , CPU - .


- . Settings -> Advanced . , . , Cold Boot. .


AVD


GPU , - GPU, . , . Cold Boot.



, . .


- . , .


')

Source: https://habr.com/ru/post/433604/


All Articles