New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 705137 link

Starred by 1 user

Issue metadata

Status: Fixed
Owner:
Last visit 15 days ago
Closed: Apr 2017
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 3
Type: Bug



Sign in to add a comment

Memory estimator doesn't take into account sharing of ProtoValuePtr field values in EntryKernel

Project Member Reported by stanisc@chromium.org, Mar 24 2017

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.
 
Blocking: 705134

Comment 2 by dskiba@chromium.org, 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. 
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.
Blocking: -705134

Comment 5 by dskiba@chromium.org, Apr 18 2017

Status: Started (was: Assigned)

Comment 6 by dskiba@chromium.org, Apr 21 2017

Indeed, the overestimation was significant - 3.3MiB -> 2.5MiB on macOS with my personal profile.
Project Member

Comment 7 by bugdroid1@chromium.org, 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

Comment 8 by dskiba@chromium.org, Apr 26 2017

Status: Fixed (was: Started)

Sign in to add a comment