ConstraintLayout performance

ConstraintLayout has been here for a while already, though just recently it become stable with a non-beta release 1.0.0. The reason it has been created is mainly performance — ConstraintLayout provides all kinds of relations between views, enabling completely flat structure (ConstraintLayout itself is the only parent in the views hierarchy).
In this article we’ll be using the newest version version 1.0.2 to test it performance against other most common variants, so we’ve got 3 test cases :
1) LinearLayout and FrameLayout,
2) RelativeLayout,
3) ConstraintLayout.

In order to perform the test, we need to have a common UI which will be represented by different layouts.

Here’s how it looks like :

A typical list item with one large ImageView, several TextViews and some ImageView icons.

Now, not to spoil the article with xml files, here you can find different implementations of this UI :

1) LinearLayout and FrameLayout xml file,
2) RelativeLayout xml file,
3) ConstraintLayout xml file.

The test performs following steps — inflate, measure and layout. Here’s the code.

So, here are the results — an average for 10000 iterations on a Android 7.1.2 Nexus5X device (time in ms, the lower the better):

  • LinearLayout & FrameLayout : 3.006ms,
  • RelativeLayout : 2.8914ms,
  • ConstraintLayout : 2.606ms.

Not really a surprise — since ConstraintLayout is intended to be performant thanks to it’s flat structure — it really is the fastest. The test shows that ConstraintLayout performs the best, about 10% better than the second — RelativeLayout. That, with all the tooling that Android Studio provides for ConstraintLayout, makes it a reasonable choice for creating layouts.

19.07.2018 — Update

ConstraintLayout is being constantly updated so I decided to rerun tests for newer versions. This time I used Samsung S8 running Android 7.0.

Results for ConstraintLayout 1.1.2 :

  • LinearLayout & FrameLayout : 1.9064ms
  • ConstraintLayout : 1.6737ms
  • RelativeLayout : 1.5449ms

Looks like for version 1.1.2 ConstraintLayout performs worse than RelativeLayout. That’s a surprise. I suppose adding new features had an impact on ConstraintLayout performance.

There’s also another ConstraintLayout version Google is working on — 2.0.0.

Results for 2.0.0-alpha1 :

  • LinearLayout & FrameLayout : 1.8770ms
  • ConstraintLayout : 2.1394ms
  • RelativeLayout : 1.5149ms

For this one, ConstraintLayout performs not only the worst among tested variants, but it’s also worse than in version 1.1.2. Of course, it’s still alpha version, however I’d expect version 2.0.0 to be a significant improvement. Let’s wait for final 2.0.0 release and see what the result are.