-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
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.