DescriptionTake 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. #
Messages
Total messages: 16 (4 generated)
|