Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(111)

Issue 2106283004: Allocate space in StringBuilder for m_string and the new bytes. (Closed)

Created:
4 years, 5 months ago by esprehn
Modified:
4 years, 5 months ago
Reviewers:
haraken, jbroman
CC:
blink-reviews, blink-reviews-wtf_chromium.org, chromium-reviews, Mikhail
Base URL:
https://chromium.googlesource.com/chromium/src.git@master
Target Ref:
refs/pending/heads/master
Project:
chromium
Visibility:
Public.

Description

Allocate space in StringBuilder for m_string and the new bytes. StringBuilder has an optimization to just store the first String object you append to avoid a copy in cases where you only append one String and then call toString(), for example if there's onlyone Text child and you do element.textContent. When appending the second string we then allocate a Vector buffer and copy the first string (m_string) into it. We weren't allocating extra space for the bytes we were about to append in the second string though, which meant we always did an extra copy immediately following the the buffer creation: String first; String second; StringBuilder builder; // No copy, just stores a pointer to first. builder.append(first); // 1. Creates a Vector // 2. Copies first into it. // 3. Appends second to the Vector which causes a Vector resize. builder.append(second); We solve this by calling reserveInitialCapacity with m_length + the number of bytes we're about to append when we created the buffer. We also inflate the number of bytes to be at least the inline capacity size so that doing: builder.append(first); builder.append('1'); builder.append('2'); doesn't require an immediate resize for appending '2' by ensuring we always overallocate the Vector by at least the inline capacity size so even when appending a String you get 16 chars of extra space to insert something else. BUG=624642 Committed: https://crrev.com/464918ccc62d3a70a976b3c38b5ef6ce6e552f31 Cr-Commit-Position: refs/heads/master@{#403407}

Patch Set 1 #

Total comments: 2
Unified diffs Side-by-side diffs Delta from patch set Stats (+34 lines, -22 lines) Patch
M third_party/WebKit/Source/wtf/text/StringBuilder.h View 3 chunks +13 lines, -10 lines 1 comment Download
M third_party/WebKit/Source/wtf/text/StringBuilder.cpp View 5 chunks +21 lines, -12 lines 1 comment Download

Messages

Total messages: 16 (6 generated)
commit-bot: I haz the power
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.org/2106283004/1
4 years, 5 months ago (2016-06-30 20:04:53 UTC) #2
commit-bot: I haz the power
Dry run: Try jobs failed on following builders: win_chromium_rel_ng on master.tryserver.chromium.win (JOB_FAILED, http://build.chromium.org/p/tryserver.chromium.win/builders/win_chromium_rel_ng/builds/248740)
4 years, 5 months ago (2016-06-30 21:41:05 UTC) #4
esprehn
https://codereview.chromium.org/2106283004/diff/1/third_party/WebKit/Source/wtf/text/StringBuilder.h File third_party/WebKit/Source/wtf/text/StringBuilder.h (right): https://codereview.chromium.org/2106283004/diff/1/third_party/WebKit/Source/wtf/text/StringBuilder.h#newcode209 third_party/WebKit/Source/wtf/text/StringBuilder.h:209: static unsigned initialBufferSize() { return kInlineBufferSize; } You have ...
4 years, 5 months ago (2016-06-30 23:23:15 UTC) #6
haraken
LGTM https://codereview.chromium.org/2106283004/diff/1/third_party/WebKit/Source/wtf/text/StringBuilder.cpp File third_party/WebKit/Source/wtf/text/StringBuilder.cpp (right): https://codereview.chromium.org/2106283004/diff/1/third_party/WebKit/Source/wtf/text/StringBuilder.cpp#newcode138 third_party/WebKit/Source/wtf/text/StringBuilder.cpp:138: m_buffer8->reserveInitialCapacity(m_length + std::max(addedSize, initialBufferSize())); I don't quite see ...
4 years, 5 months ago (2016-07-01 02:01:03 UTC) #8
esprehn
On 2016/07/01 at 02:01:03, haraken wrote: > LGTM > > https://codereview.chromium.org/2106283004/diff/1/third_party/WebKit/Source/wtf/text/StringBuilder.cpp > File third_party/WebKit/Source/wtf/text/StringBuilder.cpp (right): ...
4 years, 5 months ago (2016-07-01 02:11:34 UTC) #9
esprehn
> > ... > > I don't quite see any reason you want to take ...
4 years, 5 months ago (2016-07-01 02:15:40 UTC) #10
haraken
On 2016/07/01 02:15:40, esprehn wrote: > > > ... > > > I don't quite ...
4 years, 5 months ago (2016-07-01 02:16:56 UTC) #11
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.org/2106283004/1
4 years, 5 months ago (2016-07-01 02:39:20 UTC) #13
commit-bot: I haz the power
Committed patchset #1 (id:1)
4 years, 5 months ago (2016-07-01 04:00:48 UTC) #14
commit-bot: I haz the power
4 years, 5 months ago (2016-07-01 04:02:51 UTC) #16
Message was sent while issue was closed.
Patchset 1 (id:??) landed as
https://crrev.com/464918ccc62d3a70a976b3c38b5ef6ce6e552f31
Cr-Commit-Position: refs/heads/master@{#403407}

Powered by Google App Engine
This is Rietveld 408576698