Skip to content

Remove the annoying const lints from flutter_lints #833

@goderbauer

Description

@goderbauer

In theory, const-ness should give apps a performance boost, but during development the lints enforcing const are constantly nagging developers: "Make this const" or "This cannot be const anymore". To evaluate whether we are making the right trade-offs here between annoyingness and performance we ran some benchmarks (see flutter/flutter#149932). The benchmarks have not shown sufficient evidence to suggest that there is a statistically significant difference in performance between const and nonconst for real world apps1. Given these results, the lints that constantly nag developers during development are not carrying their weight and I suggest we remove them from the flutter_lints set. People can still manually enable them for their app, if they like.

Lints suggested for removal from the flutter_lints set (they can still be enabled manually):

  • prefer_const_constructors
  • prefer_const_literals_to_create_immutables
  • prefer_const_declarations

I suggest we keep the forth const lint (prefer_const_constructors_in_immutables) because it is very narrow in scope and generally doesn't cause any pain during development. It also enables downstream consumers to make their own choice of whether they want to create a const instance of a widget or not.

Footnotes

  1. In a contrived benchmark that did not represent real world usage in Flutter apps we were able to show that const in general can give you a small performance advantage.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Triage backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions