Skip to content

write! generate longer assembly compared to format! #82508

Open
@pickfire

Description

@pickfire
use std::fmt::Write;

let mut s = String::new();
write!(s, "{}", 1);

seemed to be generate more assembly compared to:

let mut s = String::new();
let v = format!("{}", 1);
s.push_str(&v);

For the above example, https://rust.godbolt.org/z/KPdra8

A larger example available at https://rust.godbolt.org/z/TcsbMK

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-fmtArea: `core::fmt`C-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchI-heavyIssue: Problems and improvements with respect to binary size of generated code.I-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