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

Issue 914396 link

Starred by 1 user

Issue metadata

Status: Assigned
Owner:
User never visited
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 3
Type: Task



Sign in to add a comment

syncer::MetadataBatch should support moving by value

Project Member Reported by mamir@chromium.org, Dec 12

Issue description

Protos are movable nowadays.

MetadataBatch::AddMetadata() [1] incurs unnecessary copy.

This should be changed to support moving by value or by std::unique_ptr<>



[1] https://cs.chromium.org/chromium/src/components/sync/model/metadata_batch.cc?sq=package:chromium&dr=Ss&g=0&l=28

 
I'm not sure what the proposal is -- not passing the proto in by const reference?
The alternative would be to pass-by-value and let the compiler optimize this. Not sure this is worth the effort.
I'm quite strongly against taking the parameter rvalue reference (&&) as that makes the api hard to use and complex.

If you really want to save a copy here, simply use emplace() instead of insert() on the map.

That said, I'm afraid we're looking into premature optimizations.
The two options proposed here are:

1- Pass-by-value so the caller can std::move().
2- Pass using std::unique_ptr<>.



P3 seems appropriate here but this one is also a very low-hanging fruit, because:
a) We don't have many callers to this API (4 calling sites).
b) Metadata loading happens during browser's startup and incurring in one copy (and I think today we may incur in two) may mean ~300 KB of RAM for a user with 1000 sync entities in total across all datatypes. Startup is precisely a time when resource optimization is worth.

I would personally prefer std::unique_ptr<> which we already do in other similar APIs.
sounds reasonable. I wish we could actually measure this.
sorry for the noise.
Status: Available (was: Untriaged)

Comment 6 by mastiz@chromium.org, Jan 17 (5 days ago)

Labels: Sync-Triaged Hotlist-GoodFirstBug
Owner: mmoskvitim@google.com
Status: Assigned (was: Available)

Sign in to add a comment