Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Intel® Hardware Accelerated Execution Manager

28 Nov 2013 1  
Intel’s HAXM greatly reduces the emulators boot up time and in my tests the Atom x86 based emulators performed twice as fast as their ARM counterparts

This article is in the Product Showcase section for our sponsors at CodeProject. These articles are intended to provide you with information on products and services that we consider useful and of value to developers.

Introduction

I am building a card game application for Android which has a computer AI component. Generally when I am writing code after implementing a feature or fixing a bug I like to run the code to make sure that it's working as expected. As a result I often find myself uploading, installing and running the app on an emulator. Also, when making User Interface (UI) changes I often have to launch multiple emulators to make sure that the UI works on a variety of screen sizes and resolutions. Since my UI is mostly implemented in code rather than XML this task becomes rather time consuming when using slow booting emulators.

Having spent close to a year developing this app I have gotten used to the relatively slow load times of the emulator, but I always wished it were faster. So when I got the opportunity to look at the Intel Developer Zone for Android I was interested in HAXM because it promised to speed up emulator boot times. Before proceeding with the install I thought I would benchmark the load times of my current set up. Right now I am running Windows 7 on Intel i7 920 @ 2,67 GHz with 9 GB of RAMand GeForce GTX 260. My app is about 2 MB including all the assets.

I've loaded up my project and quickly realized that my API level was below the minimum required. This meant I had to upgrade the API to level 17. I was a little concerned about this as I wanted my app to run on the lowest possible API level to make sure it is compatible with most devices, but after some consideration I realized that if I used the API to run the emulators and not reference any of its features the upgrade would do no harm. The API upgrade from level 16 to 17 took about 15 minutes to complete and I had to reboot Eclipse to be able to target Android Virtual Devices (AVD) to the new API. Once the upgrade was complete I was ready to run the tests. (Mind you the test results will vary depending on your AVD configuration and underlying hardware.)

Test #1 - Boot AVD, upload and install an app

It took 2 minutes and 15 seconds to boot a new device and upload the app. The device boot alone took almost 2 minutes. This may seem terrible, but I imagine most developers don't actually reboot the device every time and just upload their app.

Test #2 - Upload and install an app on a running AVD

Now that the AVD was up and running I made a tiny code change in order to force an upload next time I run the app. The upload and installation took 25 seconds.

Test #3 - Run an app in debug mode

For this test the code was not changed and I simply launched the app using F11. I set a breakpoint inside the onCreate method, which is the first activity that gets loaded when the app starts. This test was completed in a respectable 8 seconds.

Test #4 - Run an app in debug mode after a code change

After making a tiny code change to force a fresh upload I launched the app from Eclipse using F11. This time it took 21 seconds to hit the same breakpoint as in the test above. I was surprised to see this run faster than test #2, but I guess the breakpoint gets hit before the UI is loaded, which could explain the faster time.

Now it was time to set up Intel's HAXM. I followed the instructions provided on the website and found them pretty straightforward. The download was quick, but I found it was inconvenient that you had to complete the installation manually outside of the SDK Manager. The instructions mentioned that the install file was downloaded to the extras directory under the main SDK directory, but having set up my SDK some time ago I had to spend time looking for the downloaded file. For me I found the file under: C:\Users\yloginov\AppData\Local\Android\android-sdk\extras\intel\Hardware_Accelerated_Execution_Manager. I completed the setup and made sure that the HAXM service was running.

Following the installation I went back into the AVD Manager and created a device that targets Intel Atom (x86) processor.

Now I re-ran the tests with the new AVD.

Test #1 - Boot AVD, upload and install an app

This time it took 38 seconds! Wow. Now that's what I am talking about. In the log cat output I noticed a line that said, "HAX is working and emulator runs in fast virt mode". I guess that's what was missing before.

Test #2 - Upload and install an app on a running AVD

This test ran in nine seconds, a significant improvement on the time we saw earlier.

Test #3 - Run an app in debug mode

The test took about three seconds this time around. I hit F11, started my stop watch, looked at the screen and I was already at the breakpoint.

Test #4 - Run an app in debug mode after a code change

Eight seconds! Again, another big improvement!

Now that I was utilizing HAXM I was getting blazing fast emulator times and that makes me happy. Overall the performance gain is significant and noticeable to the naked eye. If you need to upgrade the API to run HAXM I would recommend doing so carefully and confirming that your project is compiling prior to proceeding with the HAXM install. In the end even though I spent a few hours trying to get this whole thing up and running I think it was time well spent! Another cool thing to note is that HAXM also runs on MAC.

HAXM Usability

Prior to installing Intel’s HAXM, uploading and installing an app on an emulator was a bit of a bottleneck in my development workflow. I would implement a feature and be excited about testing it out on an emulator, but then would have to wait over 20 seconds for it to load. This may not seem like a long time, but it really takes the wind out of your sails when you are on a roll and churning out code. If I want a coffee break I will take one, I don’t need my build tool to provide me with one every time I compile and run the code. I like to be able to write some code, press the run button and instantly see the changes that I’ve made. This HAXM tool from Intel allows you to do just that. It really pays off when you deploy your code and it breaks, but you know that you made a silly mistake and it’s a one second fix. On your regular emulator you make the change and wait for the upload again. With HAXM you can skip the waiting part. The same is true for debugging the source code. If you are making small changes between launching the app in debug mode you could eliminate the annoying upload times and get right into eliminating bugs.

My app creates a lot of the UI and animations during run time by instantiating Views rather than defining them in XML. Generally if you use XML to define your layout you can see the changes in Eclipse without launching the emulator. However, that’s not the case when the layout is created programmatically. I chose not to use XML-based views because programmatically declared views give you more control and run faster since there is no need to parse the XML file. The drawback of this approach was that I had to run the app every time I wanted to see how the UI would look. This becomes especially bothersome if you are only making small tweaks like changing the height of the button from 50 DPI to 60 DPI. This slowed me down quite a bit at first, but after installing HAXM it’s basically no longer an issue. Now I can change the layout as I please and see the changes almost instantly. One thing to watch out for is not uploading your .apk file to the emulator too often in a short period of time. Eclipse will say there is an error in your project, even though there isn't one. I suspect it’s somehow related to memory allocation, but didn’t research it enough to say for sure. Generally, restarting Eclipse resolves this issue.

Like most Android developers I am concerned about how my app will look on a variety of devices. This concern usually grows as the release date approaches. Luckily AVDs let us get a sneak preview of our app without actually owning the hardware. This sounds great, but there is a catch: starting a fresh emulator takes a painfully long time. Starting an emulator from scratch took over two minutes on my machine. Generally I like to test my app on all screen densities and ideally across different resolutions on the same density. This means that I would need at least six different emulators and that list grows every time a new device hits the market. Of course one option is to boot all the emulators at once, but that would require a beast of a machine with lots of RAM. This means most of us will have to settle for running only a couple of AVDs in parallel and then closing them down to make room for a new set of AVDs. Intel’s HAXM greatly reduces the emulators boot up time and in my tests the Atom x86 based emulators performed twice as fast as their ARM counterparts. This is a very solid gain and should not be taken lightly.

To install Intel® HAXM, visit the Intel Developer Zone for Android

Other Related Articles

To learn more about Intel tools for the Android developer, visit Intel® Developer Zone for Android.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here