New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 695333 link

Starred by 1 user

Issue metadata

Status: Started
Owner:
Long OOO (go/where-is-mgiuca)
Components:
EstimatedDays: ----
NextAction: ----
OS: All
Pri: 3
Type: Bug



Sign in to add a comment

base::JoinString might reallocate/copy string many times

Project Member Reported by mgiuca@chromium.org, Feb 23 2017

Issue description

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.
 
Project Member

Comment 1 by bugdroid1@chromium.org, Mar 2 2017

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/130c60771ce2b0a3e6ef84046905a7f00fcdb2dd

commit 130c60771ce2b0a3e6ef84046905a7f00fcdb2dd
Author: mgiuca <mgiuca@chromium.org>
Date: Thu Mar 02 05:59:50 2017

base::JoinString: Pre-allocate the string to its final size.

This avoids re-allocation/copying costs as the string is constructed.

BUG=695333

Review-Url: https://codereview.chromium.org/2709983006
Cr-Commit-Position: refs/heads/master@{#454189}

[modify] https://crrev.com/130c60771ce2b0a3e6ef84046905a7f00fcdb2dd/base/strings/string_util.cc

Sign in to add a comment