-
Notifications
You must be signed in to change notification settings - Fork 13.7k
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.
Description
I was slightly surprised to see that code like this:
pub fn foo() {
format!("Hello {}", 4);
}
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 String
and 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.
matthiaskrgr, Aaron1011, hwmack, alecmocatta, pickfire and 4 more
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.