Does using "String" instead of "&str" a lot results in unoptimised code?

59 points SnooMacaroons3057

I'll try to explain what's happening.

I have a global state, like redis which stores all the online users, and their usernames, email, user_id etc in a HashMap as a String.

A request comes in to message that user, that also has to do with storing the message in database - I spawn a new tokio::task and clone the user's username, email, user_id string to move into that task.

After sending the message, the task has to store the message in the database, which again has to have the fields username, email... into the database. After the fields are saved, I am sending a response back to the socket for the confirmation, and that includes one more .clone() call on all these fields.

Is this a bad architecture? Is clone() that big of an issue for small strings?