Skip to content

Lint for inefficient Quiver check statements #58796

@alanrussian

Description

@alanrussian

Describe the rule you'd like to see implemented

While profiling my team's code, I noticed we were spending a significant amount of time on constructing the message for check statements that we weren't even tripping. The reason was that we were using string interpolation and calling Type.toString() as part of these check statements. For example:

// Using quiver checks
checkState(someAlwaysTrueStatementInProd,
    message: '$SomeClass blah blah ${someExpensiveComputation()}');

This performance issue is easily fixable by making the message a lambda:

checkState(someAlwaysTrueStatementInProd,
    message: () => '$SomeClass blah blah ${someExpensiveComputation()}');

However, this is a common mistake developers make. We can prevent these performance regressions, and potentially speed up a bunch of existing code, by making a lint around this.

@davidmorgan suggested generalizing this lint by making a "must be const or function/lambda" lint. I like that idea and already know of other places we can reuse that in my team's codebase.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3A lower priority bug or feature requestarea-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.devexp-linterIssues with the analyzer's support for the linter packagelinter-lint-proposaltype-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions