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

Issue 2973863002: Remove std::string histogram name from HistogramBase object.

Created:
3 years, 5 months ago by bcwhite
Modified:
3 years, 3 months ago
CC:
chromium-reviews, danakj+watch_chromium.org, asvitkine+watch_chromium.org, vmpstr+watch_chromium.org
Target Ref:
refs/heads/master
Project:
chromium
Visibility:
Public.

Description

Remove std::string histogram name from HistogramBase object. The std::string implementation is frequently around 28 or 40 bytes (on 32/64-bit builds) in order to hold small strings without having to allocate external memory. Not only do histogram names typically exceed that amount but most strings are code constants to begin with. Also, when persistent histograms are used, the name is copied to persistent memory meaning that there are frequently 2 ram copies of code constant strings and 28 bytes of space wasted per histogram object. Instead, keep only a "const char*" for the histogram name and use other mechanisms to ensure its permanence should it not be persistent and not be a code constant. The resulting savings is 24 (of 64) bytes in HistogramBase on 32-bit builds and 32 (of 104) bytes on 64-bit. The Histogram object is thus reduced from 88/136 bytes to 64/104 bytes. Basically, the size of all Histogram objects is cut in half plus a reduction in external strings. These measurements were done on Windows. Other implementations of std::string may not have the small-string optimization and thus the reduction may be as little as one machine word. BUG=733380 CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.android:android_optional_gpu_tests_rel;master.tryserver.chromium.linux:linux_optional_gpu_tests_rel;master.tryserver.chromium.mac:mac_optional_gpu_tests_rel;master.tryserver.chromium.win:win_optional_gpu_tests_rel

Patch Set 1 #

Patch Set 2 : rebased #

Patch Set 3 : never rely on outside string permanence #

Total comments: 2

Patch Set 4 : rebased #

Patch Set 5 : fixed outside references to histogram_name() #

Patch Set 6 : fixed outside references to histogram_name() #

Patch Set 7 : rebased #

Patch Set 8 : rebased #

Patch Set 9 : rebased #

Unified diffs Side-by-side diffs Delta from patch set Stats (+127 lines, -86 lines) Patch
M base/metrics/histogram.h View 1 2 3 4 5 6 7 8 11 chunks +14 lines, -14 lines 0 comments Download
M base/metrics/histogram.cc View 1 2 3 4 5 6 7 8 17 chunks +24 lines, -27 lines 0 comments Download
M base/metrics/histogram_base.h View 1 2 3 3 chunks +16 lines, -3 lines 0 comments Download
M base/metrics/histogram_base.cc View 1 2 3 3 chunks +20 lines, -4 lines 0 comments Download
M base/metrics/histogram_base_unittest.cc View 5 chunks +5 lines, -5 lines 0 comments Download
M base/metrics/histogram_snapshot_manager.cc View 1 2 3 4 5 6 7 1 chunk +1 line, -1 line 0 comments Download
M base/metrics/persistent_histogram_allocator.cc View 1 2 3 4 5 6 7 8 1 chunk +1 line, -1 line 0 comments Download
M base/metrics/sparse_histogram.h View 2 chunks +3 lines, -3 lines 0 comments Download
M base/metrics/sparse_histogram.cc View 4 chunks +5 lines, -7 lines 0 comments Download
M base/metrics/sparse_histogram_unittest.cc View 2 chunks +2 lines, -2 lines 0 comments Download
M base/metrics/statistics_recorder.cc View 1 2 3 4 5 6 7 8 3 chunks +11 lines, -6 lines 0 comments Download
M base/metrics/statistics_recorder_unittest.cc View 1 2 3 4 5 6 7 8 1 chunk +1 line, -1 line 0 comments Download
M chromecast/base/metrics/grouped_histogram.cc View 1 2 3 4 5 chunks +12 lines, -7 lines 0 comments Download
M extensions/browser/value_store/lazy_leveldb.h View 1 2 3 4 5 6 1 chunk +1 line, -1 line 0 comments Download
M extensions/browser/value_store/leveldb_value_store.cc View 1 2 3 4 5 1 chunk +1 line, -1 line 0 comments Download
M third_party/webrtc_overrides/init_webrtc.cc View 1 2 3 4 5 1 chunk +1 line, -1 line 0 comments Download
M tools/metrics/histograms/histograms.xml View 1 2 3 4 5 6 7 8 1 chunk +9 lines, -0 lines 0 comments Download
M ui/gl/angle_platform_impl.cc View 1 2 3 2 chunks +0 lines, -2 lines 0 comments Download

Messages

Total messages: 53 (48 generated)
bcwhite
Let me know what you think of this. It's not something I'd want to submit ...
3 years, 5 months ago (2017-07-06 20:29:02 UTC) #3
Alexei Svitkine (slow)
I like the idea in principle, but I worry about it being too error-prone for ...
3 years, 5 months ago (2017-07-12 21:43:15 UTC) #12
bcwhite
On 2017/07/12 21:43:15, Alexei Svitkine (slow) wrote: > I like the idea in principle, but ...
3 years, 5 months ago (2017-07-12 22:44:37 UTC) #13
Alexei Svitkine (slow)
https://codereview.chromium.org/2973863002/diff/40001/base/metrics/histogram_base.cc File base/metrics/histogram_base.cc (right): https://codereview.chromium.org/2973863002/diff/40001/base/metrics/histogram_base.cc#newcode191 base/metrics/histogram_base.cc:191: char const* HistogramBase::GetPermanentName(const std::string& name) { Can we avoid ...
3 years, 5 months ago (2017-07-17 21:34:44 UTC) #23
bcwhite
3 years, 5 months ago (2017-07-18 01:07:16 UTC) #24
https://codereview.chromium.org/2973863002/diff/40001/base/metrics/histogram_...
File base/metrics/histogram_base.cc (right):

https://codereview.chromium.org/2973863002/diff/40001/base/metrics/histogram_...
base/metrics/histogram_base.cc:191: char const*
HistogramBase::GetPermanentName(const std::string& name) {
On 2017/07/17 21:34:43, Alexei Svitkine (slow) wrote:
> Can we avoid having an extra temporary string constructed for when the
original
> input is a literal?
> 
> I believe with your CL, it currently works thus:
> 
> HISTOGRAM_*() macro calls const char* version of FactoryGet(). Which then
> creates a std::string and calls regular version of FactoryGet(), which then
> calls Factory() which stores a reference to that. Which then calls
> GetPermanentName() with that entry. Now, since name is const here, the
insert()
> call on line 199 will make a copy of the name and add it to the set.
> 
> So there's a temporary intermediate copy.
> 
> I think we can avoid this by plumbing const char* version through and then
> having the std::string be created just here on line 199 and so no extra
> temporary needed.

We might also be able to make the name parameter be a "moveable" string to avoid
the copy.  That would probably need a lot of fixes throughout the code, though,
so probably not worth the effort.

And of course, std::string is free to do internal optimizations, too, though I
don't know if it does any.

I'd need two GetPermanentName() methods: one that takes std::string (for when
it's a constructed name) and one that takes const char*... though taking
std::string&& (i.e. movable) might be even better as it would allow the former
to call the latter with a copy rather than duplicate the logic.

Is it worth it considering that persistence is now the 100% default and so this
extra-copy path only gets called when persistence hasn't yet been enabled or
when the memory buffer is full?

Powered by Google App Engine
This is Rietveld 408576698