Memory estimator doesn't take into account sharing of ProtoValuePtr field values in EntryKernel |
||||
Issue description
ProtoValuePtr was specifically designed to share actual content of proto fields in EntryKernel. These fields are identical 99% of the time so the current approach would result in significant overestimation by as much as a few KB per EntryKernel instance.
The code below it seems just adds size of all specifics_fields elements together which in most cases would result in doubling (and potentially even tripling) the estimated size.
size_t EntryKernel::EstimateMemoryUsage() const {
if (memory_usage_ == kMemoryUsageUnknown) {
using base::trace_event::EstimateMemoryUsage;
memory_usage_ = EstimateMemoryUsage(string_fields) +
EstimateMemoryUsage(specifics_fields) + <----- Here
EstimateMemoryUsage(id_fields) +
EstimateMemoryUsage(unique_position_fields) +
EstimateMemoryUsage(attachment_metadata_fields); <----- Here
}
return memory_usage_;
}
A better approach is to compare the underlying value address for equality. It is OK to test consecutive elements only e.g. specifics_fields[0] to specifics_fields[1] or specifics_fields[1] to specifics_fields[2].
The same applies to attachment_metadata_fields.
,
Mar 25 2017
Nice catch! Other way to fix this is to take number of references into account, i.e. divide return value by number of references wrapper_ has.
,
Mar 25 2017
Reference count isn't as reliable. Sharing is also used to create a snapshot of dirty EntryKernel instances for the database update operation. So there might be extra references for a short time.
,
Apr 10 2017
,
Apr 18 2017
,
Apr 21 2017
Indeed, the overestimation was significant - 3.3MiB -> 2.5MiB on macOS with my personal profile.
,
Apr 21 2017
The following revision refers to this bug: https://chromium.googlesource.com/chromium/src.git/+/9740714c369114929625061c17be977df4fac810 commit 9740714c369114929625061c17be977df4fac810 Author: dskiba <dskiba@chromium.org> Date: Fri Apr 21 19:26:12 2017 [sync] Properly estimate EntryKernel memory usage. BUG= 705137 Review-Url: https://codereview.chromium.org/2837513002 Cr-Commit-Position: refs/heads/master@{#466411} [modify] https://crrev.com/9740714c369114929625061c17be977df4fac810/components/sync/syncable/entry_kernel.cc
,
Apr 26 2017
|
||||
►
Sign in to add a comment |
||||
Comment 1 by martiniss@chromium.org
, Mar 24 2017