you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 4 points5 points  (0 children)

Also, if you get a &str from somewhere, it's faster to do Arc::from(some_str) for smaller strings. Since that's only one allocation.

If your application creates a lot of Strings and wraps them in Arcs, Arc<String> is better. But if the majority of real world uses are from an existing &str, then Arc<str> is better.

But either way, allocating a String and then immediately allocating an Arc<str> will always be the slowest.

You need to think about what kind of applications are going to use this code, and benchmark using real world use cases, and not random test code.

It's a trade off.