Ever wondered how Xamarin.Android performance stacks against code written in Java? We did.
As an introduction, let’s refresh Xamarin.Android architecture. While on Apple iOS Xamarin code is compiled into native code, on Android things work differently. Xamarin code runs inside a VM which works side-by-side with Java VM running Dalvik code. Hence, since Xamarin does not need to go through JVM, it could in theory work as quickly as even faster than Java. In reality, Xamarin apps will be larger than Java apps, since there is a need to bundle the Xamarin runtime.
- Let’s examine overhead of Xamarin runtime. In order to do this, we built a simple “Hello World!” app. The app size is under 2 MB.
- Startup time for native Java apps is better than for Xamarin. While a small Java application starts almost immediately, our Xamarin app takes a second.
- Integer and floating multiplication written in Java are about 20% quicker.
- Operations with collections are almost 10 times faster on Xamarin than on Java, because Java lacks struct value type.
- String manipulations under Xamarin are about four (4) times faster than code written in Android-native Java.