base::JoinString is pretty naive; it just creates a string and then starts appending parts onto the end. This can result in potentially log(N) reallocations/copies.
string::reserve should be used to initialize the string to its full length before appending pieces, so there is exactly 1 allocation and 1 copy of all the string pieces.
Note: We have our own implementation of JoinString in share_service_impl.cc:
https://cs.chromium.org/chromium/src/chrome/browser/webshare/share_service_impl.cc?l=35
which does the reserve. This implementation is being folded into base::JoinString (https://codereview.chromium.org/2691193002), so it will temporarily regress in this regard.
Comment 1 by bugdroid1@chromium.org
, Mar 2 2017