Flutter: Performance analysis of `const` constructor

Crizant Lai
Nerd For Tech

--

Everyone says using const constructors improves the performance of your app, but how much? I haven’t found any analysis on the internet, so I decide to do it myself.

Here is my app for the test:

An app display a random moving Flutter logo

Method

During the test i will create two screens to display the moving logo, one of them uses the const constructor of Image widget:

const Image(
width: 100,
height: 100,
image: AssetImage('assets/logo.png'),
)

And the other one without the const keyword.

The logo is wrapped inside a AnimatedPositioned widget, and its position is updated once per second.

Then we run the app by using the --profile flag, and inspect the “performance” and “memory” tab in Dart DevTools.

Performance overlay of Flutter

In each round of the test, I will increase the number of logos in the screen, to study the performance difference with or without using the const constructor.

--

--

Nerd For Tech
Nerd For Tech

Published in Nerd For Tech

NFT is an Educational Media House. Our mission is to bring the invaluable knowledge and experiences of experts from all over the world to the novice. To know more about us, visit https://www.nerdfortech.org/.

Crizant Lai
Crizant Lai

Written by Crizant Lai

A TypeScript/Flutter developer who love technical stuffs.