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

Issue 1063933002: Take a StringPiece when looking up CommandLine switches. (Closed)

Created:
5 years, 8 months ago by jackhou1
Modified:
5 years, 7 months ago
Reviewers:
tapted, brettw
CC:
chromium-reviews, tfarina, erikwright+watch_chromium.org, chrome-apps-syd-reviews_chromium.org
Base URL:
https://chromium.googlesource.com/chromium/src.git@cmd
Target Ref:
refs/pending/heads/master
Project:
chromium
Visibility:
Public.

Description

Take a StringPiece when looking up CommandLine switches. This avoids the string allocation when searching for a char* in a std::map<std::string>. CommandLine now maintains a parallel map of StringPieces that reference the strings in |switches_|. StringPiece is trivial to construct from a string, and only requires a strlen to construct from a char*. On a profile with 2 extensions, HasSwitch is called ~12k times during startup. In an ideal situation (no paging/cache pressure), the string allocation under Windows takes ~137ns on a Xeon E5-2690 @ 2.9Ghz. A strlen on a typical switch takes about 50ns, and 91% of calls pass a char*, so there's a net saving of at least (137 - 0.9 * 50)ns * 12k = 1.1ms from a typical startup with this hardware. For context, Startup.BrowserMessageLoopStartTimeFromMainEntry is typically 280-300ms on the same hardware, so we should get a ~0.4% improvement. BUG=472383 Committed: https://crrev.com/1bd9da921215cca875ec3610db0976ac7ed9909a Cr-Commit-Position: refs/heads/master@{#330902}

Patch Set 1 #

Patch Set 2 : Include https://codereview.chromium.org/1046363002/ #

Patch Set 3 : Fix compile on Linux. #

Patch Set 4 : Fix test on Linux. #

Patch Set 5 : Don't use emplace. #

Patch Set 6 : Don't change SwitchMap to maintain GetSwitches semantics. #

Patch Set 7 : Fix on Linux. Add test for existng switch. #

Patch Set 8 : Fix on Windows. #

Patch Set 9 : Override copy and assign. #

Total comments: 17

Patch Set 10 : Address comments. #

Total comments: 4

Patch Set 11 : Address comments. #

Patch Set 12 : Sync and rebase #

Total comments: 10

Patch Set 13 : Address comments #

Patch Set 14 : Sync and rebase. #

Unified diffs Side-by-side diffs Delta from patch set Stats (+92 lines, -35 lines) Patch
M base/command_line.h View 1 2 3 4 5 6 7 8 9 10 11 12 6 chunks +26 lines, -7 lines 0 comments Download
M base/command_line.cc View 1 2 3 4 5 6 7 8 9 10 11 12 7 chunks +43 lines, -26 lines 0 comments Download
M base/command_line_unittest.cc View 1 2 3 4 5 6 7 8 9 10 11 6 chunks +23 lines, -2 lines 0 comments Download

Messages

Total messages: 16 (4 generated)
tapted
https://codereview.chromium.org/1063933002/diff/180001/base/command_line.cc File base/command_line.cc (right): https://codereview.chromium.org/1063933002/diff/180001/base/command_line.cc#newcode146 base/command_line.cc:146: void ResetStringPieces( needs a comment https://codereview.chromium.org/1063933002/diff/180001/base/command_line.cc#newcode280 base/command_line.cc:280: std::string(switch_string.data(), switch_string.size())), ...
5 years, 8 months ago (2015-04-15 00:07:53 UTC) #3
jackhou1
https://codereview.chromium.org/1063933002/diff/180001/base/command_line.cc File base/command_line.cc (right): https://codereview.chromium.org/1063933002/diff/180001/base/command_line.cc#newcode146 base/command_line.cc:146: void ResetStringPieces( On 2015/04/15 00:07:53, tapted wrote: > needs ...
5 years, 8 months ago (2015-04-17 00:56:10 UTC) #4
tapted
code lg but the CL description needs some sciencey numbers in it to provide rationale, ...
5 years, 8 months ago (2015-04-17 01:14:33 UTC) #5
jackhou1
https://codereview.chromium.org/1063933002/diff/200001/base/command_line.cc File base/command_line.cc (right): https://codereview.chromium.org/1063933002/diff/200001/base/command_line.cc#newcode151 base/command_line.cc:151: std::map<base::StringPiece, const CommandLine::StringType*>* On 2015/04/17 01:14:33, tapted (OOO until ...
5 years, 8 months ago (2015-04-22 04:09:42 UTC) #6
jackhou1
brettw, could you take a look? This is the follow-up to: "Enforce lowercase switches when ...
5 years, 8 months ago (2015-04-22 06:01:37 UTC) #8
brettw
https://codereview.chromium.org/1063933002/diff/240001/base/command_line.cc File base/command_line.cc (right): https://codereview.chromium.org/1063933002/diff/240001/base/command_line.cc#newcode149 base/command_line.cc:149: void ResetStringPieces( Why not make this a private member ...
5 years, 8 months ago (2015-04-24 19:50:50 UTC) #9
jackhou1
brettw, thanks for reviewing. Apologies for the long hiatus as I was on vacation. PTAL ...
5 years, 7 months ago (2015-05-11 13:51:42 UTC) #10
jackhou1
brettw, ping
5 years, 7 months ago (2015-05-19 02:47:53 UTC) #11
brettw
lgtm
5 years, 7 months ago (2015-05-20 20:33:47 UTC) #12
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1063933002/280001
5 years, 7 months ago (2015-05-21 01:32:32 UTC) #14
commit-bot: I haz the power
Committed patchset #14 (id:280001)
5 years, 7 months ago (2015-05-21 04:48:07 UTC) #15
commit-bot: I haz the power
5 years, 7 months ago (2015-05-21 04:49:53 UTC) #16
Message was sent while issue was closed.
Patchset 14 (id:??) landed as
https://crrev.com/1bd9da921215cca875ec3610db0976ac7ed9909a
Cr-Commit-Position: refs/heads/master@{#330902}

Powered by Google App Engine
This is Rietveld 408576698