Book Image

Learning Xamarin studio

By : William Smith
Book Image

Learning Xamarin studio

By: William Smith

Overview of this book

Table of Contents (16 chapters)
Learning Xamarin Studio
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Improving AVD performance


Once you've had the opportunity to work with one of the AVDs, you will notice right away that they are very sluggish during their initial startup, and only marginally faster on subsequent startups. This behavior is consistent on both Mac and Windows machines running Intel chipsets, but it seems to be especially true on Windows. However, don't be discouraged by this initial performance because there are steps that can be taken to significantly improve this.

Note

All of the performance measurements cited in this section are averages based on tests performed on my personal development machine. For example, I tested my user-defined Nexus 7 AVD and clocked an average initial start up time of just over 3 minutes, and an average subsequent start up time of just over 2 minutes. These average measurements will serve as the benchmarks for later testing and comparison.

Intel x86 Atom System Image

Most Android devices run ARM processors. Likewise, the out-of-the-box AVDs are based on the ARM system image called the APM EABI v7a System Image. Although the ARM processor architecture is highly efficient and suitable for mobile device applications, it is also quite different from Intel architecture. As a result, the ARM system image performs very poorly when emulated on an Intel chipset.

Intel is aware of this performance issue and has responded by creating its own system image called Intel x86 Atom System Image. This image was designed for the specific purpose of running AVDs on Intel-based machines, and it can significantly improve AVD startup and operational performance. The only drawback is Intel x86 Atom is not available for every target API level at this time.

Let's create a new AVD from scratch, but this time target the Intel x86 Atom System Image:

  1. Inside Xamarin Studio, go to Tools | Open SDK Manager.

  2. Once the SDK Manager opens, go to Tools | Manage Add-On Sites.

  3. Select the User Defined Sites tab.

  4. Confirm that the Android x86 System Image property exists.

    • If not, click the New button

    • Enter https://dl-ssl.google.com/android/repository/sys-img/x86/sys-img.xml and click OK

  5. Close the Add-on Sites dialog.

  6. Confirm that the Sort by property at the bottom of the dialog window is set to API Level.

  7. Scroll down and expand the Android 4.4.2 (API 19) group.

  8. Select the Intel x86 Atom System Image checkbox.

  9. Click Install 1 package.

  10. Once this package is installed, you may close the SDK Manager.

  11. Inside Xamarin Studio, go to Tools | Open AVD Manager.

  12. Select the Device Definitions tab.

  13. Select the Nexus 7 by Google image.

  14. Click the Create AVD button.

  15. In the AVD Name field, type AVD_for_Nexus_7_by_Google.

  16. From the Target drop-down list, select Android 4.4.2 – API Level 19.

  17. From the CPU/ABI drop-down list, select Intel Atom (x86). Now, your dialog should resemble the following screenshot:

  18. Leave all of the other settings at their default values and click OK.

Try using your new Nexus 7 AVD and compare the speed to that of the original, ARM-based AVD. You should see a marked improvement in both startup and operational performance.

Hardware Acceleration Execution Manager

So, you've tried out your new Nexus 7 AVD running on the Inter x86 Atom image. Now you're thinking, "This is good, but can it be better?". To coin a phrase, "Gentlemen, we can rebuild it. We have the technology."

If you are running a fairly up-to-date computer with an Intel chip that has Intel® Virtualization Technology enabled, you can utilize the Intel Hardware Acceleration Execution Manager (HAXM). HAXM is capable of easily improving performance by an order of magnitude. Coupled with an AVD built on the Intel x86 Atom system image, the improvement is almost astounding.

Note

Note that there is a specific hardware prerequisite to use this technology. Your machine, whether it is Mac OS or Windows, must have an Intel processor with support for Intel VT-x, EM64T and Execute Disable (XD) Bit functionality enabled in Basic Input/Output System (BIOS).

AXM can be installed in three steps. First, you need to make sure that virtualization technology is enabled in the BIOS. Then, you need to install the HAXM add-on through the SDK Manager. Finally, you need to run the executable for your system.

Since virtualization technology is typically turned on by default on most systems, we'll start by installing the HAXM add-on through the SDK Manager by using the following steps:

  1. Inside Xamarin Studio, go to Tools | Open SDK Manager.

  2. Once SDK Manager opens, go to Tools | Manage Add-On Sites.

  3. Select the User Defined Sites tab.

  4. Confirm that the Intel HAXM property exists.

    • If not, click the New button

    • Enter https://dl-ssl.google.com/android/repository/extras/intel/addon.xml and click OK

  5. Close the Add-on Sites dialog.

  6. Confirm that the Sort by property at the bottom of the dialog window is set to API Level.

  7. Scroll down and expand the Extras group.

  8. Select the Intel x86 Emulator Accelerator (HAXM) checkbox.

  9. Click Install 1 package.

  10. Once this package is installed, you can close the SDK Manager.

    Note

    You may have noticed that the HAXM entry in SDK Manager was listed as Installed when you were finished. This is just poor design on the part of the SDK Manager, in my opinion, because the package is not fully installed quite yet. To do this, we need to launch the HAXM executable.

  11. Open Finder (or Explorer in Windows) and navigate to <sdk>/extras/intel/Hardware_Accelerated_Execution_Manager/.

  12. From here, launch IntelHAXM.dmg (IntelHAXM.exe in Windows).

  13. Proceed through the HAXM installation process. When you reach the screen titled Memory Limit for Intel HAXM, it's best to just leave the default setting for now as you can go back and change it later if necessary. Setting this value too high initially can cause poor performance in other applications on your system while the HAXM is running.

    Note

    If during the installation you receive an error message stating that Intel® Virtualization Technology is not turned on, you will need to enable it in BIOS before you can proceed. Enter your system's BIOS settings, set Virtualization Technology: [Enabled], and then restart the executable.

At this stage, you should be enjoying much faster performance of your AVDs. In fact, HAXM can make those AVDs based on the Intel x86 Atom image run at near native speeds! Initial startup of the AVD takes around 25 seconds on my machine, while subsequent startups take around 17 seconds. There's still one more item we can tweak in our AVD setup to squeeze out just a little more startup performance.

Run from Snapshot

If you edit one of your AVD definitions, at the bottom you will see a group titled Emulation Options. Within that group there are two options that improve performance, Snapshot and Use Host GPU. One improves start up performance and the other improves general operating performance. Unfortunately, you can only use one of these improvements at a time. For the sake of our discussion, let's assume we are more concerned with faster start up times, so we will set the option to Snapshot:

  1. Inside Xamarin Studio, go to Tools | Open AVD Manager.

  2. Select the Device Definitions tab.

  3. Select the Nexus 7 by Google image.

  4. Click Create AVD.

  5. Change the AVD Name field.

  6. From the Target drop-down list, select Android 4.4.2 – API Level 19.

  7. From the CPU/ABI drop-down list, select Intel Atom (x86).

  8. In the Emulation Options group, select Snapshot as shown in the following screenshot:

  9. Leave all of the other settings at their default values and click OK.

This new AVD is based on the Intel x86 Atom system image and is set to run from Snapshot. As long as HAXM is running on our system, your initial start up time will still be about the same, but subsequent startups should clock in much faster. On my development machine, start up time still averaged about 25 seconds, but subsequent start up times averaged 5 seconds! Now when your fellow developers tell you that the AVDs running on the packaged SDK are painfully sluggish, you'll know they just haven't applied themselves to finding a solution to the problem.

Third-party AVD options

Do you still feel the need for more speed? No worries, I won't judge. At this stage, if you want to improve performance even further, you need to start looking at alternatives to the SDK Emulator platform. There are several third-party packages that provide comparable and, in some cases, even better performance over the SDK emulators. GenyMotion is one popular alternative that is currently available for free to individual developers and small companies. GenyMotion provides an alternative to the entire emulator paradigm, replacing emulation with virtualization. I personally use the GenyMotion Free edition and I have been very pleased with its performance.

Note

GenyMotion, as well as any other alternative to AVD emulation, is not essential software for working in Xamarin Studio. Therefore, installing and setting up the software is beyond the scope of this book. However, if you are interested in trying out GenyMotion, you can download and try out the free version at https://shop.genymotion.com/index.php? controller=order-opc.