Skip to content

"".to_string() is slower than String::new() #18404

Description

@cgaebel

In a lot of rust code, I see "".to_string() being used as the default method of creating a new string. This would normally be fine, but it's actually noticeably slower than String::new() because it goes through the formatting infrastructure.

It'd be nice if this pattern could be special-cased in String::to_string's implementation, or the optimizer made to do this transformation better.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-collectionsArea: `std::collections`I-slowIssue: Problems and improvements with respect to performance of generated code.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions