Tips and Tricks for the new D8 Compiler from our R&D Team

As you know the new D8 dexer became the default one starting from Android Studio / Android Gradle Plugin 3.1. If your application can be targeted to minSDK >= 19, you can decrease the size of Dalvik byte code for array initialization operations.

Initializing an array is a quite frequent thing in the development of Java and Android applications. So getting the byte code optimized is useful here.

// Define a projection that specifies which columns from the database
// you will actually use after this query.
String[] projection = {
BaseColumns._ID,
FeedEntry.COLUMN_NAME_TITLE,
FeedEntry.COLUMN_NAME_SUBTITLE
};

As you can see, it is tighter due to the fact that instead of performing 3 operations of putting a string into the array, we put indexes of strings which takes 2 16-bit units versus 5 16-bit units with DX.

We have seen so many constructions of that kind in the real world applications, and we are almost sure you have got them too. So why not to get this zero-cost optimization? The size of the byte code should decrease, and the launch time, and performance should become better.