-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-codegenArea: Code generationArea: Code generationA-fmtArea: `core::fmt`Area: `core::fmt`C-bugCategory: This is a bug.Category: This is a bug.C-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-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
Description
I tried this code:
pub fn func(i: i32) -> String {
format!("{}", &i)
}
I expected &i
to be inlined and be equivalent to format!("{}", i)
Instead, in my benchmarking tests I see about 6% performance hit, and assembly has a non-inlined function.
Relevant links
- Assembly comparison
- Benchmarking code
- A Clippy lint: A new lint to remove unneeded arg referencing in a format! rust-clippy#10851
- Stackoverflow question
Meta
rustc --version --verbose
:
rustc 1.69.0 (84c898d65 2023-04-16)
binary: rustc
commit-hash: 84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc
commit-date: 2023-04-16
host: x86_64-unknown-linux-gnu
release: 1.69.0
LLVM version: 15.0.7
drahnr
Metadata
Metadata
Assignees
Labels
A-codegenArea: Code generationArea: Code generationA-fmtArea: `core::fmt`Area: `core::fmt`C-bugCategory: This is a bug.Category: This is a bug.C-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-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.