Commit f28b4304 authored by Liquan(Max) Gu's avatar Liquan(Max) Gu Committed by Commit Bot

[FCP++] Performance: avoid creating ID for unrelated nodes

FCP++ uses IdForNode() to get node ID. But IdForNode() has the side effect of
creating an id for node if it doesn't exist. As FCP++ uses IdForNode() for
every removed node regardless of whether it's content node, it's a costly
operation.

FCP++ only cares about the removal of the nodes that have already been
recorded. This indicates that the nodes already have node id. Based on
this characteristic, FCP++ can ignore the nodes that do not have node id, so
as to reduce cost.

This CL is to implement this idea.

Bug: 945405
Change-Id: I03602d3d79f5f5ed4c087a7a2cf0a44aec1accbb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1540263
Commit-Queue: Liquan (Max) Gu <maxlg@chromium.org>
Reviewed-by: default avatarXianzhu Wang <wangxianzhu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#644869}
parent 89b4b764
......@@ -10,6 +10,12 @@ namespace blink {
DEFINE_WEAK_IDENTIFIER_MAP(Node, DOMNodeId)
// static
DOMNodeId DOMNodeIds::ExistingIdForNode(Node* node) {
return node ? WeakIdentifierMap<Node, DOMNodeId>::ExistingIdentifier(node)
: kInvalidDOMNodeId;
}
// static
DOMNodeId DOMNodeIds::IdForNode(Node* node) {
return node ? WeakIdentifierMap<Node, DOMNodeId>::Identifier(node)
......
......@@ -19,6 +19,7 @@ class CORE_EXPORT DOMNodeIds {
STATIC_ONLY(DOMNodeIds);
public:
static DOMNodeId ExistingIdForNode(Node*);
static DOMNodeId IdForNode(Node*);
static Node* NodeForId(DOMNodeId);
};
......
......@@ -38,6 +38,10 @@ class WeakIdentifierMap final
return result;
}
static IdentifierType ExistingIdentifier(T* object) {
return Instance().object_to_identifier_.at(object);
}
static T* Lookup(IdentifierType identifier) {
return Instance().identifier_to_object_.at(identifier);
}
......
......@@ -85,9 +85,9 @@ void PaintTimingDetector::NotifyTextPaint(
}
void PaintTimingDetector::NotifyNodeRemoved(const LayoutObject& object) {
if (!object.GetNode())
DOMNodeId node_id = DOMNodeIds::ExistingIdForNode(object.GetNode());
if (node_id == kInvalidDOMNodeId)
return;
DOMNodeId node_id = DOMNodeIds::IdForNode(object.GetNode());
text_paint_timing_detector_->NotifyNodeRemoved(node_id);
image_paint_timing_detector_->NotifyNodeRemoved(node_id);
}
......
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