Skip to content

Optimize performance by using write_str instead of write! when there are no formatting arguments #285

@nyurik

Description

@nyurik

Apparently when using write!("anything without arguments"), the compiler generates considerable additional code, resulting in bigger binaries and likely slower performance. I tried it with https://rust.godbolt.org/z/Y8djWsq1P

I would like to replace write!(f, ...) with f.write_str(...) in the generated code.

P.S. This issue is also tracked in rust-lang/rust#99012 - but it appears to be highly complex and nowhere near being solved in a near future, thus warranting a workaround at least in the popular crates.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions