Commit 7391e1db authored by Sigurdur Asgeirsson's avatar Sigurdur Asgeirsson Committed by Chromium LUCI CQ

PM: More efficient flat_set construction.

Bug: 1164947
Change-Id: I5a4cc3521ede1b8032cad26800c28efbf9a1fabd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2621917
Commit-Queue: Sigurður Ásgeirsson <siggi@chromium.org>
Auto-Submit: Sigurður Ásgeirsson <siggi@chromium.org>
Reviewed-by: default avatarJoe Mason <joenotcharles@chromium.org>
Cr-Commit-Position: refs/heads/master@{#842535}
parent 8d7ce656
...@@ -59,6 +59,7 @@ static_library("performance_manager") { ...@@ -59,6 +59,7 @@ static_library("performance_manager") {
"graph/graph_impl.h", "graph/graph_impl.h",
"graph/graph_impl_operations.cc", "graph/graph_impl_operations.cc",
"graph/graph_impl_operations.h", "graph/graph_impl_operations.h",
"graph/graph_impl_util.h",
"graph/graph_operations.cc", "graph/graph_operations.cc",
"graph/graph_registered.cc", "graph/graph_registered.cc",
"graph/node.cc", "graph/node.cc",
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "components/performance_manager/graph/graph_impl.h" #include "components/performance_manager/graph/graph_impl.h"
#include "components/performance_manager/graph/graph_impl_util.h"
#include "components/performance_manager/graph/page_node_impl.h" #include "components/performance_manager/graph/page_node_impl.h"
#include "components/performance_manager/graph/process_node_impl.h" #include "components/performance_manager/graph/process_node_impl.h"
#include "components/performance_manager/graph/worker_node_impl.h" #include "components/performance_manager/graph/worker_node_impl.h"
...@@ -414,11 +415,8 @@ bool FrameNodeImpl::VisitChildFrameNodes( ...@@ -414,11 +415,8 @@ bool FrameNodeImpl::VisitChildFrameNodes(
const base::flat_set<const FrameNode*> FrameNodeImpl::GetChildFrameNodes() const base::flat_set<const FrameNode*> FrameNodeImpl::GetChildFrameNodes()
const { const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
base::flat_set<const FrameNode*> children;
for (auto* child : child_frame_nodes()) return UpcastNodeSet<FrameNode>(child_frame_nodes());
children.insert(static_cast<const FrameNode*>(child));
DCHECK_EQ(children.size(), child_frame_nodes().size());
return children;
} }
bool FrameNodeImpl::VisitOpenedPageNodes(const PageNodeVisitor& visitor) const { bool FrameNodeImpl::VisitOpenedPageNodes(const PageNodeVisitor& visitor) const {
...@@ -434,11 +432,7 @@ bool FrameNodeImpl::VisitOpenedPageNodes(const PageNodeVisitor& visitor) const { ...@@ -434,11 +432,7 @@ bool FrameNodeImpl::VisitOpenedPageNodes(const PageNodeVisitor& visitor) const {
const base::flat_set<const PageNode*> FrameNodeImpl::GetOpenedPageNodes() const base::flat_set<const PageNode*> FrameNodeImpl::GetOpenedPageNodes()
const { const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
base::flat_set<const PageNode*> opened; return UpcastNodeSet<PageNode>(opened_page_nodes());
for (auto* page : opened_page_nodes())
opened.insert(static_cast<const PageNode*>(page));
DCHECK_EQ(opened.size(), opened_page_nodes().size());
return opened;
} }
FrameNodeImpl::LifecycleState FrameNodeImpl::GetLifecycleState() const { FrameNodeImpl::LifecycleState FrameNodeImpl::GetLifecycleState() const {
...@@ -484,11 +478,7 @@ bool FrameNodeImpl::IsHoldingIndexedDBLock() const { ...@@ -484,11 +478,7 @@ bool FrameNodeImpl::IsHoldingIndexedDBLock() const {
const base::flat_set<const WorkerNode*> FrameNodeImpl::GetChildWorkerNodes() const base::flat_set<const WorkerNode*> FrameNodeImpl::GetChildWorkerNodes()
const { const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
base::flat_set<const WorkerNode*> children; return UpcastNodeSet<WorkerNode>(child_worker_nodes());
for (auto* child : child_worker_nodes())
children.insert(static_cast<const WorkerNode*>(child));
DCHECK_EQ(children.size(), child_worker_nodes().size());
return children;
} }
bool FrameNodeImpl::VisitChildDedicatedWorkers( bool FrameNodeImpl::VisitChildDedicatedWorkers(
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_PERFORMANCE_MANAGER_GRAPH_GRAPH_IMPL_UTIL_H_
#define COMPONENTS_PERFORMANCE_MANAGER_GRAPH_GRAPH_IMPL_UTIL_H_
#include "base/containers/flat_set.h"
namespace performance_manager {
template <typename PublicNodeClass, typename NodeImplClass>
base::flat_set<const PublicNodeClass*> UpcastNodeSet(
const base::flat_set<NodeImplClass*>& node_set) {
// As node_set is a flat_set, its contents are sorted and unique already.
return base::flat_set<const PublicNodeClass*>(
base::sorted_unique, node_set.begin(), node_set.end());
}
} // namespace performance_manager
#endif // COMPONENTS_PERFORMANCE_MANAGER_GRAPH_GRAPH_IMPL_UTIL_H_
...@@ -6,42 +6,23 @@ ...@@ -6,42 +6,23 @@
#include "components/performance_manager/graph/frame_node_impl.h" #include "components/performance_manager/graph/frame_node_impl.h"
#include "components/performance_manager/graph/graph_impl_operations.h" #include "components/performance_manager/graph/graph_impl_operations.h"
#include "components/performance_manager/graph/graph_impl_util.h"
#include "components/performance_manager/graph/page_node_impl.h" #include "components/performance_manager/graph/page_node_impl.h"
#include "components/performance_manager/graph/process_node_impl.h" #include "components/performance_manager/graph/process_node_impl.h"
namespace performance_manager { namespace performance_manager {
namespace {
template <typename ImplContainerType, typename PublicContainerType>
PublicContainerType ConvertContainer(const ImplContainerType& impls) {
PublicContainerType result;
for (auto* impl : impls) {
// Use the hinting insert, which all containers support. This will result
// in the same ordering for vectors, and for containers that are sorted it
// will actually provide the optimal hint. For hashed containers this
// parameter will be ignored so is effectively a nop.
result.insert(result.end(), impl);
}
return result;
}
} // namespace
// static // static
base::flat_set<const PageNode*> GraphOperations::GetAssociatedPageNodes( base::flat_set<const PageNode*> GraphOperations::GetAssociatedPageNodes(
const ProcessNode* process) { const ProcessNode* process) {
return ConvertContainer<base::flat_set<PageNodeImpl*>, return UpcastNodeSet<PageNode>(GraphImplOperations::GetAssociatedPageNodes(
base::flat_set<const PageNode*>>( ProcessNodeImpl::FromNode(process)));
GraphImplOperations::GetAssociatedPageNodes(
ProcessNodeImpl::FromNode(process)));
} }
// static // static
base::flat_set<const ProcessNode*> GraphOperations::GetAssociatedProcessNodes( base::flat_set<const ProcessNode*> GraphOperations::GetAssociatedProcessNodes(
const PageNode* page) { const PageNode* page) {
return ConvertContainer<base::flat_set<ProcessNodeImpl*>, return UpcastNodeSet<ProcessNode>(
base::flat_set<const ProcessNode*>>(
GraphImplOperations::GetAssociatedProcessNodes( GraphImplOperations::GetAssociatedProcessNodes(
PageNodeImpl::FromNode(page))); PageNodeImpl::FromNode(page)));
} }
...@@ -49,9 +30,8 @@ base::flat_set<const ProcessNode*> GraphOperations::GetAssociatedProcessNodes( ...@@ -49,9 +30,8 @@ base::flat_set<const ProcessNode*> GraphOperations::GetAssociatedProcessNodes(
// static // static
std::vector<const FrameNode*> GraphOperations::GetFrameNodes( std::vector<const FrameNode*> GraphOperations::GetFrameNodes(
const PageNode* page) { const PageNode* page) {
return ConvertContainer<std::vector<FrameNodeImpl*>, auto impls = GraphImplOperations::GetFrameNodes(PageNodeImpl::FromNode(page));
std::vector<const FrameNode*>>( return std::vector<const FrameNode*>(impls.begin(), impls.end());
GraphImplOperations::GetFrameNodes(PageNodeImpl::FromNode(page)));
} }
// static // static
......
...@@ -4,8 +4,6 @@ ...@@ -4,8 +4,6 @@
#include "components/performance_manager/public/graph/node.h" #include "components/performance_manager/public/graph/node.h"
#include "components/performance_manager/graph/node_base.h"
namespace performance_manager { namespace performance_manager {
Node::Node() = default; Node::Node() = default;
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/check_op.h" #include "base/check_op.h"
#include "components/performance_manager/graph/frame_node_impl.h" #include "components/performance_manager/graph/frame_node_impl.h"
#include "components/performance_manager/graph/graph_impl.h" #include "components/performance_manager/graph/graph_impl.h"
#include "components/performance_manager/graph/graph_impl_util.h"
#include "components/performance_manager/graph/page_node_impl.h" #include "components/performance_manager/graph/page_node_impl.h"
#include "components/performance_manager/graph/worker_node_impl.h" #include "components/performance_manager/graph/worker_node_impl.h"
#include "components/performance_manager/public/execution_context/execution_context_registry.h" #include "components/performance_manager/public/execution_context/execution_context_registry.h"
...@@ -241,23 +242,12 @@ bool ProcessNodeImpl::VisitFrameNodes(const FrameNodeVisitor& visitor) const { ...@@ -241,23 +242,12 @@ bool ProcessNodeImpl::VisitFrameNodes(const FrameNodeVisitor& visitor) const {
base::flat_set<const FrameNode*> ProcessNodeImpl::GetFrameNodes() const { base::flat_set<const FrameNode*> ProcessNodeImpl::GetFrameNodes() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
base::flat_set<const FrameNode*> frames; return UpcastNodeSet<FrameNode>(frame_nodes());
const base::flat_set<FrameNodeImpl*>& frame_impls = frame_nodes();
for (auto* frame_impl : frame_impls) {
const FrameNode* frame = frame_impl;
frames.insert(frame);
}
return frames;
} }
base::flat_set<const WorkerNode*> ProcessNodeImpl::GetWorkerNodes() const { base::flat_set<const WorkerNode*> ProcessNodeImpl::GetWorkerNodes() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
base::flat_set<const WorkerNode*> workers; return UpcastNodeSet<WorkerNode>(worker_nodes_);
for (auto* worker_impl : worker_nodes_) {
const WorkerNode* worker = worker_impl;
workers.insert(worker);
}
return workers;
} }
bool ProcessNodeImpl::GetMainThreadTaskLoadIsLow() const { bool ProcessNodeImpl::GetMainThreadTaskLoadIsLow() const {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment