Flutter: Performance analysis of `const` constructor
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:
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.
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.