Skip to content

Using &v instead of v arg in format! does not inline, causing ~6% perf hit #112156

Open
@nyurik

Description

@nyurik

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.

image

Relevant links

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-codegenArea: Code generationA-fmtArea: `core::fmt`C-bugCategory: This is a bug.C-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchI-slowIssue: 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.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions