ConstraintLayout performance

Piotr Krystyniak
May 27, 2017 · 3 min read

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 :

Image for post
Image for post

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.
Image for post
Image for post

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 :

Image for post
Image for post
  • 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 :

Image for post
Image for post
  • 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.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store