-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Unused format!()s are not optimised away #75742
Copy link
Copy link
Open
Labels
A-mir-optArea: MIR optimizationsArea: MIR optimizationsC-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchCategory: An issue highlighting optimization opportunities or PRs implementing suchI-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-mir-optArea: MIR optimizationsArea: MIR optimizationsC-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchCategory: An issue highlighting optimization opportunities or PRs implementing suchI-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
I was slightly surprised to see that code like this:
does not get optimised to a nop. It still calls
format!(). This is surprising from a user point of view - you're calling a function, but it seems like it has no side effects and I don't use the result, so surely it should be removed?I presume the reason it doesn't is that it allocates a
Stringand heap allocation is considered to be a side effect? Whatever the reason I think that it would be nice if it was optimised.If you're wondering about motivation, consider a debug trait with a default implementation that does nothing. You could call
debug.write(&format!(...))and it would be fully optimised away for the default implementation.