Migrate `ProcessorEntityTracker` maps to `absl::flat_hash_map` [chromium/src : main]

0 views
Skip to first unread message

Ankush Singh (Gerrit)

unread,
Aug 27, 2025, 11:37:58 AM (13 days ago) Aug 27
to Michael Tatarski, AyeAye, Marc Treib, Chromium LUCI CQ, tracing...@chromium.org, wfh+...@chromium.org, droger+w...@chromium.org, spang...@chromium.org
Attention needed from Marc Treib and Michael Tatarski

Ankush Singh added 1 comment

File components/sync/model/processor_entity_tracker.h
Line 14, Patchset 2 (Latest):#include "absl/container/flat_hash_map.h"
Ankush Singh . unresolved

Just a fly-by: `third_party/abseil-cpp/absl/container/flat_hash_map.h` plus removes the change in DEPS.

Open in Gerrit

Related details

Attention is currently required from:
  • Marc Treib
  • Michael Tatarski
Submit Requirements:
  • requirement satisfiedCode-Coverage
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedNo-Unresolved-Comments
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: chromium/src
Gerrit-Branch: main
Gerrit-Change-Id: I95ca62c8dfbf9b9fc20f6201d896bdd58136ecb3
Gerrit-Change-Number: 6891231
Gerrit-PatchSet: 2
Gerrit-Owner: Michael Tatarski <mtat...@google.com>
Gerrit-Reviewer: Marc Treib <tr...@chromium.org>
Gerrit-Reviewer: Michael Tatarski <mtat...@google.com>
Gerrit-CC: Ankush Singh <ankus...@google.com>
Gerrit-Attention: Michael Tatarski <mtat...@google.com>
Gerrit-Attention: Marc Treib <tr...@chromium.org>
Gerrit-Comment-Date: Wed, 27 Aug 2025 15:37:44 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
satisfied_requirement
unsatisfied_requirement
open
diffy

Michael Tatarski (Gerrit)

unread,
Aug 27, 2025, 11:45:18 AM (13 days ago) Aug 27
to Ankush Singh, AyeAye, Marc Treib, Chromium LUCI CQ, tracing...@chromium.org, wfh+...@chromium.org, droger+w...@chromium.org, spang...@chromium.org
Attention needed from Ankush Singh and Marc Treib

Michael Tatarski voted and added 2 comments

Votes added by Michael Tatarski

Auto-Submit+1
Commit-Queue+1

2 comments

Patchset-level comments
File-level comment, Patchset 2:
Michael Tatarski . resolved

Thank you ;)

File components/sync/model/processor_entity_tracker.h
Line 14, Patchset 2:#include "absl/container/flat_hash_map.h"
Ankush Singh . resolved

Just a fly-by: `third_party/abseil-cpp/absl/container/flat_hash_map.h` plus removes the change in DEPS.

Michael Tatarski

Done

Open in Gerrit

Related details

Attention is currently required from:
  • Ankush Singh
  • Marc Treib
Submit Requirements:
  • requirement satisfiedCode-Coverage
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: chromium/src
Gerrit-Branch: main
Gerrit-Change-Id: I95ca62c8dfbf9b9fc20f6201d896bdd58136ecb3
Gerrit-Change-Number: 6891231
Gerrit-PatchSet: 3
Gerrit-Owner: Michael Tatarski <mtat...@google.com>
Gerrit-Reviewer: Marc Treib <tr...@chromium.org>
Gerrit-Reviewer: Michael Tatarski <mtat...@google.com>
Gerrit-CC: Ankush Singh <ankus...@google.com>
Gerrit-Attention: Marc Treib <tr...@chromium.org>
Gerrit-Attention: Ankush Singh <ankus...@google.com>
Gerrit-Comment-Date: Wed, 27 Aug 2025 15:45:01 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Comment-In-Reply-To: Ankush Singh <ankus...@google.com>
satisfied_requirement
unsatisfied_requirement
open
diffy

Marc Treib (Gerrit)

unread,
Aug 27, 2025, 11:59:43 AM (13 days ago) Aug 27
to Michael Tatarski, Ankush Singh, AyeAye, Marc Treib, Chromium LUCI CQ, tracing...@chromium.org, wfh+...@chromium.org, droger+w...@chromium.org, spang...@chromium.org
Attention needed from Ankush Singh and Michael Tatarski

Marc Treib added 5 comments

Patchset-level comments
File-level comment, Patchset 2:
Michael Tatarski . resolved

These changes touch critical pieces of sync infra. I want to get the approval of the TL for this CL!

This should unlock a significant performance gain as we move from O(log(N)) to (1) TC behaviour in our internal sync data structures.

Marc Treib

significant performance gain

I'll believe that when you show me the timing measurements! :P

But the absl containers are generally recommended as the default these days, and AFAIK they have essentially no downsides compared to the std ones, so this is still a good change to make overall.

File base/trace_event/memory_usage_estimator.h
Line 647, Patchset 2:
for (const auto& pair : map) {
memory_usage += EstimateItemMemoryUsage(pair.first);
memory_usage += EstimateItemMemoryUsage(pair.second);
}
Marc Treib . unresolved

Won't this double-count the memory?
If we do need to iterate over the elements, could this use `EstimateIterableMemoryUsage`?

Line 645, Patchset 2: // plus control bytes (capacity * sizeof(char)).
Marc Treib . unresolved
File components/sync/base/client_tag_hash.h
Line 32, Patchset 2: // For use in absl::flat_hash_set.
Marc Treib . unresolved

`or absl::flat_hash_set`, right?

File components/sync/model/processor_entity_tracker.h
Line 147, Patchset 3 (Latest): entities_;
Marc Treib . unresolved

Just a note: This will change the ordering of the elements. I'm pretty sure that's fine, since (a) the ordering was arbitrary anyway, and (b) none of the usages seem to care about the order.
But out of curiosity: Did you check all the usages?

Open in Gerrit

Related details

Attention is currently required from:
  • Ankush Singh
  • Michael Tatarski
Submit Requirements:
    • requirement satisfiedCode-Coverage
    • requirement is not satisfiedCode-Owners
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: chromium/src
    Gerrit-Branch: main
    Gerrit-Change-Id: I95ca62c8dfbf9b9fc20f6201d896bdd58136ecb3
    Gerrit-Change-Number: 6891231
    Gerrit-PatchSet: 3
    Gerrit-Owner: Michael Tatarski <mtat...@google.com>
    Gerrit-Reviewer: Marc Treib <tr...@chromium.org>
    Gerrit-Reviewer: Michael Tatarski <mtat...@google.com>
    Gerrit-CC: Ankush Singh <ankus...@google.com>
    Gerrit-Attention: Michael Tatarski <mtat...@google.com>
    Gerrit-Attention: Ankush Singh <ankus...@google.com>
    Gerrit-Comment-Date: Wed, 27 Aug 2025 15:59:27 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Comment-In-Reply-To: Michael Tatarski <mtat...@google.com>
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    Michael Tatarski (Gerrit)

    unread,
    Aug 27, 2025, 12:16:03 PM (13 days ago) Aug 27
    to Ankush Singh, AyeAye, Marc Treib, Chromium LUCI CQ, tracing...@chromium.org, wfh+...@chromium.org, droger+w...@chromium.org, spang...@chromium.org
    Attention needed from Ankush Singh and Marc Treib

    Michael Tatarski voted and added 5 comments

    Votes added by Michael Tatarski

    Auto-Submit+1
    Commit-Queue+1

    5 comments

    Patchset-level comments
    File-level comment, Patchset 4 (Latest):
    Michael Tatarski . resolved

    WDYT if I measure the performance difference and present it in our "Technical discussion / knowledge sharing" meeting?

    File base/trace_event/memory_usage_estimator.h
    Line 647, Patchset 2:
    for (const auto& pair : map) {
    memory_usage += EstimateItemMemoryUsage(pair.first);
    memory_usage += EstimateItemMemoryUsage(pair.second);
    }
    Marc Treib . resolved

    Won't this double-count the memory?
    If we do need to iterate over the elements, could this use `EstimateIterableMemoryUsage`?

    Michael Tatarski

    The calculation is done in two parts:

    **map.capacity() * (sizeof(value_type) + sizeof(char)):** This accounts for the memory allocated by the flat_hash_map itself to hold the std::pair elements.

    **The iteration over elements:** This sums up any memory that is dynamically allocated by the elements themselves (e.g., the character buffer for a std::string key or value).
    This is consistent with how memory is estimated for other containers in this file.

    However, you are right that the loop can be simplified by using EstimateIterableMemoryUsage

    Line 645, Patchset 2: // plus control bytes (capacity * sizeof(char)).
    Marc Treib . resolved
    Michael Tatarski

    Done

    File components/sync/base/client_tag_hash.h
    Line 32, Patchset 2: // For use in absl::flat_hash_set.
    Marc Treib . resolved

    `or absl::flat_hash_set`, right?

    Michael Tatarski

    Right! But you mean `absl::flat_hash_map`, correct?

    File components/sync/model/processor_entity_tracker.h
    Line 147, Patchset 3: entities_;
    Marc Treib . resolved

    Just a note: This will change the ordering of the elements. I'm pretty sure that's fine, since (a) the ordering was arbitrary anyway, and (b) none of the usages seem to care about the order.
    But out of curiosity: Did you check all the usages?

    Michael Tatarski

    Yes, none of the usages rely on the map being sorted! Most of the time we just want to find a random element or we are simply iterating over a map.

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Ankush Singh
    • Marc Treib
    Submit Requirements:
    • requirement satisfiedCode-Coverage
    • requirement is not satisfiedCode-Owners
    • requirement is not satisfiedCode-Review
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: chromium/src
    Gerrit-Branch: main
    Gerrit-Change-Id: I95ca62c8dfbf9b9fc20f6201d896bdd58136ecb3
    Gerrit-Change-Number: 6891231
    Gerrit-PatchSet: 4
    Gerrit-Owner: Michael Tatarski <mtat...@google.com>
    Gerrit-Reviewer: Marc Treib <tr...@chromium.org>
    Gerrit-Reviewer: Michael Tatarski <mtat...@google.com>
    Gerrit-CC: Ankush Singh <ankus...@google.com>
    Gerrit-Attention: Marc Treib <tr...@chromium.org>
    Gerrit-Attention: Ankush Singh <ankus...@google.com>
    Gerrit-Comment-Date: Wed, 27 Aug 2025 16:15:44 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: Yes
    Comment-In-Reply-To: Marc Treib <tr...@chromium.org>
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    Marc Treib (Gerrit)

    unread,
    Aug 27, 2025, 12:35:09 PM (13 days ago) Aug 27
    to Michael Tatarski, Marc Treib, Ankush Singh, AyeAye, Chromium LUCI CQ, tracing...@chromium.org, wfh+...@chromium.org, droger+w...@chromium.org, spang...@chromium.org
    Attention needed from Ankush Singh and Michael Tatarski

    Marc Treib voted and added 3 comments

    Votes added by Marc Treib

    Code-Review+1

    3 comments

    Patchset-level comments
    Michael Tatarski . resolved

    WDYT if I measure the performance difference and present it in our "Technical discussion / knowledge sharing" meeting?

    Marc Treib

    Per my other comment, I think for this one it's not necessary - it's just following general best practices.
    (If you *want* to measure it I'm not going to stop you, but the results from that other CL would be more interesting!)

    File base/trace_event/memory_usage_estimator.h
    Line 647, Patchset 2:
    for (const auto& pair : map) {
    memory_usage += EstimateItemMemoryUsage(pair.first);
    memory_usage += EstimateItemMemoryUsage(pair.second);
    }
    Marc Treib . resolved

    Won't this double-count the memory?
    If we do need to iterate over the elements, could this use `EstimateIterableMemoryUsage`?

    Michael Tatarski

    The calculation is done in two parts:

    **map.capacity() * (sizeof(value_type) + sizeof(char)):** This accounts for the memory allocated by the flat_hash_map itself to hold the std::pair elements.

    **The iteration over elements:** This sums up any memory that is dynamically allocated by the elements themselves (e.g., the character buffer for a std::string key or value).
    This is consistent with how memory is estimated for other containers in this file.

    However, you are right that the loop can be simplified by using EstimateIterableMemoryUsage

    Marc Treib

    Ah, I had missed that `EstimateItemMemoryUsage` only counts *dynamically allocated* memory, not the memory usage of the object itself, e.g. for an `int` it'll return 0. That's quite subtle, and the naming could IMO be better, but that's definitely not for this CL.

    File components/sync/base/client_tag_hash.h
    Line 32, Patchset 2: // For use in absl::flat_hash_set.
    Marc Treib . resolved

    `or absl::flat_hash_set`, right?

    Michael Tatarski

    Right! But you mean `absl::flat_hash_map`, correct?

    Marc Treib

    Yup, indeed!

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Ankush Singh
    • Michael Tatarski
    Submit Requirements:
      • requirement satisfiedCode-Coverage
      • requirement is not satisfiedCode-Owners
      • requirement satisfiedCode-Review
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: chromium/src
      Gerrit-Branch: main
      Gerrit-Change-Id: I95ca62c8dfbf9b9fc20f6201d896bdd58136ecb3
      Gerrit-Change-Number: 6891231
      Gerrit-PatchSet: 4
      Gerrit-Owner: Michael Tatarski <mtat...@google.com>
      Gerrit-Reviewer: Marc Treib <tr...@chromium.org>
      Gerrit-Reviewer: Michael Tatarski <mtat...@google.com>
      Gerrit-CC: Ankush Singh <ankus...@google.com>
      Gerrit-Attention: Michael Tatarski <mtat...@google.com>
      Gerrit-Attention: Ankush Singh <ankus...@google.com>
      Gerrit-Comment-Date: Wed, 27 Aug 2025 16:34:52 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: Yes
      Comment-In-Reply-To: Michael Tatarski <mtat...@google.com>
      Comment-In-Reply-To: Marc Treib <tr...@chromium.org>
      satisfied_requirement
      unsatisfied_requirement
      open
      diffy

      Michael Tatarski (Gerrit)

      unread,
      Aug 28, 2025, 6:43:08 AM (12 days ago) Aug 28
      to Nico Weber, Marc Treib, Ankush Singh, AyeAye, Chromium LUCI CQ, tracing...@chromium.org, wfh+...@chromium.org, droger+w...@chromium.org, spang...@chromium.org
      Attention needed from Marc Treib, Michael Tatarski and Nico Weber

      Message from Michael Tatarski

      Set Ready For Review

      Open in Gerrit

      Related details

      Attention is currently required from:
      • Marc Treib
      • Michael Tatarski
      • Nico Weber
      Submit Requirements:
      • requirement satisfiedCode-Coverage
      • requirement is not satisfiedCode-Owners
      • requirement satisfiedCode-Review
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: chromium/src
      Gerrit-Branch: main
      Gerrit-Change-Id: I95ca62c8dfbf9b9fc20f6201d896bdd58136ecb3
      Gerrit-Change-Number: 6891231
      Gerrit-PatchSet: 6
      Gerrit-Owner: Michael Tatarski <mtat...@google.com>
      Gerrit-Reviewer: Marc Treib <tr...@chromium.org>
      Gerrit-Reviewer: Michael Tatarski <mtat...@google.com>
      Gerrit-Reviewer: Nico Weber <tha...@chromium.org>
      Gerrit-CC: Ankush Singh <ankus...@google.com>
      Gerrit-Attention: Michael Tatarski <mtat...@google.com>
      Gerrit-Attention: Marc Treib <tr...@chromium.org>
      Gerrit-Attention: Nico Weber <tha...@chromium.org>
      Gerrit-Comment-Date: Thu, 28 Aug 2025 10:42:53 +0000
      Gerrit-HasComments: No
      Gerrit-Has-Labels: No
      satisfied_requirement
      unsatisfied_requirement
      open
      diffy

      Nico Weber (Gerrit)

      unread,
      Aug 28, 2025, 8:49:50 AM (12 days ago) Aug 28
      to Michael Tatarski, Nico Weber, Marc Treib, Ankush Singh, AyeAye, Chromium LUCI CQ, tracing...@chromium.org, wfh+...@chromium.org, droger+w...@chromium.org, spang...@chromium.org
      Attention needed from Michael Tatarski

      Nico Weber voted Code-Review+1

      Code-Review+1
      Open in Gerrit

      Related details

      Attention is currently required from:
      • Michael Tatarski
      Submit Requirements:
      • requirement satisfiedCode-Coverage
      • requirement satisfiedCode-Owners
      • requirement satisfiedCode-Review
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: chromium/src
      Gerrit-Branch: main
      Gerrit-Change-Id: I95ca62c8dfbf9b9fc20f6201d896bdd58136ecb3
      Gerrit-Change-Number: 6891231
      Gerrit-PatchSet: 7
      Gerrit-Owner: Michael Tatarski <mtat...@google.com>
      Gerrit-Reviewer: Marc Treib <tr...@chromium.org>
      Gerrit-Reviewer: Michael Tatarski <mtat...@google.com>
      Gerrit-Reviewer: Nico Weber <tha...@chromium.org>
      Gerrit-CC: Ankush Singh <ankus...@google.com>
      Gerrit-Attention: Michael Tatarski <mtat...@google.com>
      Gerrit-Comment-Date: Thu, 28 Aug 2025 12:49:41 +0000
      Gerrit-HasComments: No
      Gerrit-Has-Labels: Yes
      satisfied_requirement
      open
      diffy

      Michael Tatarski (Gerrit)

      unread,
      Aug 28, 2025, 8:55:10 AM (12 days ago) Aug 28
      to Nico Weber, Marc Treib, Ankush Singh, AyeAye, Chromium LUCI CQ, tracing...@chromium.org, wfh+...@chromium.org, droger+w...@chromium.org, spang...@chromium.org

      Michael Tatarski voted Commit-Queue+2

      Commit-Queue+2
      Open in Gerrit

      Related details

      Attention set is empty
      Submit Requirements:
      • requirement satisfiedCode-Coverage
      • requirement satisfiedCode-Owners
      • requirement satisfiedCode-Review
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: chromium/src
      Gerrit-Branch: main
      Gerrit-Change-Id: I95ca62c8dfbf9b9fc20f6201d896bdd58136ecb3
      Gerrit-Change-Number: 6891231
      Gerrit-PatchSet: 7
      Gerrit-Owner: Michael Tatarski <mtat...@google.com>
      Gerrit-Reviewer: Marc Treib <tr...@chromium.org>
      Gerrit-Reviewer: Michael Tatarski <mtat...@google.com>
      Gerrit-Reviewer: Nico Weber <tha...@chromium.org>
      Gerrit-CC: Ankush Singh <ankus...@google.com>
      Gerrit-Comment-Date: Thu, 28 Aug 2025 12:54:56 +0000
      Gerrit-HasComments: No
      Gerrit-Has-Labels: Yes
      satisfied_requirement
      open
      diffy

      Chromium LUCI CQ (Gerrit)

      unread,
      Aug 28, 2025, 8:57:54 AM (12 days ago) Aug 28
      to Michael Tatarski, Nico Weber, Marc Treib, Ankush Singh, AyeAye, tracing...@chromium.org, wfh+...@chromium.org, droger+w...@chromium.org, spang...@chromium.org

      Chromium LUCI CQ submitted the change

      Change information

      Commit message:
      Migrate `ProcessorEntityTracker` maps to `absl::flat_hash_map`

      This change replaces `std::map` with `absl::flat_hash_map` for
      `entities_` and `storage_key_to_tag_hash_` in `ProcessorEntityTracker`.
      To support this, `ClientTagHash` is made compatible with Abseil hashing
      by adding an `AbslHashValue` function. Additionally, a memory usage
      estimator for `absl::flat_hash_map` is added to
      `base/trace_event/memory_usage_estimator.h`. The usage of
      `std::erase_if` is updated to `absl::erase_if` for the new container
      type.
      Bug: 441179972
      Change-Id: I95ca62c8dfbf9b9fc20f6201d896bdd58136ecb3
      Reviewed-by: Marc Treib <tr...@chromium.org>
      Auto-Submit: Michael Tatarski <mtat...@google.com>
      Reviewed-by: Nico Weber <tha...@chromium.org>
      Commit-Queue: Michael Tatarski <mtat...@google.com>
      Cr-Commit-Position: refs/heads/main@{#1507679}
      Files:
      • M base/trace_event/memory_usage_estimator.h
      • M components/sync/base/client_tag_hash.h
      • M components/sync/model/processor_entity_tracker.cc
      • M components/sync/model/processor_entity_tracker.h
      Change size: S
      Delta: 4 files changed, 29 insertions(+), 5 deletions(-)
      Branch: refs/heads/main
      Submit Requirements:
      • requirement satisfiedCode-Review: +1 by Marc Treib, +1 by Nico Weber
      Open in Gerrit
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: merged
      Gerrit-Project: chromium/src
      Gerrit-Branch: main
      Gerrit-Change-Id: I95ca62c8dfbf9b9fc20f6201d896bdd58136ecb3
      Gerrit-Change-Number: 6891231
      Gerrit-PatchSet: 8
      Gerrit-Owner: Michael Tatarski <mtat...@google.com>
      Gerrit-Reviewer: Chromium LUCI CQ <chromiu...@luci-project-accounts.iam.gserviceaccount.com>
      open
      diffy
      satisfied_requirement
      Reply all
      Reply to author
      Forward
      0 new messages