⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 274818 in webkit


Ignore:
Timestamp:
Mar 22, 2021, 4:36:35 PM (5 years ago)
Author:
Patrick Angle
Message:

REGRESSION(r272433): Inspector should not instrument inside WebCore::Node::setRenderer
https://bugs.webkit.org/show_bug.cgi?id=223559

Reviewed by Ryosuke Niwa and Devin Rousso.

Existing test coverage:

  • inspector/css/nodeLayoutContextTypeChanged.html
  • inspector/css/setLayoutContextTypeChangedMode.html

The previous approach to observing render changes was most likely a performance regression in a very hot code
path (Node::setRenderer). This patch resolves this by not instrumenting in this the hot path. Instead we call
inspector instrumentation inside the constructors/destructors of only the RenderObject subclasses we are
interested in observing layout changes for.

Additionally, layout change events are now added to a Vector of pending changes, which will be sent to the
front-end later in order to avoid evaluating JavaScript inside a destructor in WK1 with the new instrumentation
points.

  • dom/Element.cpp:

(WebCore::Element::didChangeRenderer): Deleted.

  • dom/Element.h:
  • dom/Node.h:

(WebCore::Node::didChangeRenderer): Deleted.

  • inspector/InspectorInstrumentation.cpp:

(WebCore::InspectorInstrumentation::nodeLayoutContextChangedImpl):

  • inspector/InspectorInstrumentation.h:

(WebCore::InspectorInstrumentation::nodeLayoutContextChanged):

  • inspector/agents/InspectorCSSAgent.cpp:

(WebCore::InspectorCSSAgent::InspectorCSSAgent):
(WebCore::InspectorCSSAgent::reset):
(WebCore::InspectorCSSAgent::nodeLayoutContextTypeChanged):
(WebCore::InspectorCSSAgent::layoutContextTypeChangedTimerFired):

  • Moved layout change events behind a timer firing.
  • inspector/agents/InspectorCSSAgent.h:
  • rendering/RenderGrid.cpp:

(WebCore::RenderGrid::RenderGrid):
(WebCore::RenderGrid::~RenderGrid):

  • Move instrumentation from Node::setRenderer to RenderGrid.
  • rendering/RenderObject.h:

(WebCore::Node::setRenderer):

Location:
trunk/Source/WebCore
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r274816 r274818  
     12021-03-22  Patrick Angle  <pangle@apple.com>
     2
     3        REGRESSION(r272433): Inspector should not instrument inside `WebCore::Node::setRenderer`
     4        https://bugs.webkit.org/show_bug.cgi?id=223559
     5
     6        Reviewed by Ryosuke Niwa and Devin Rousso.
     7
     8        Existing test coverage:
     9        - inspector/css/nodeLayoutContextTypeChanged.html
     10        - inspector/css/setLayoutContextTypeChangedMode.html
     11
     12        The previous approach to observing render changes was most likely a performance regression in a very hot code
     13        path (`Node::setRenderer`). This patch resolves this by not instrumenting in this the hot path. Instead we call
     14        inspector instrumentation inside the constructors/destructors of only the RenderObject subclasses we are
     15        interested in observing layout changes for.
     16
     17        Additionally, layout change events are now added to a `Vector` of pending changes, which will be sent to the
     18        front-end later in order to avoid evaluating JavaScript inside a destructor in WK1 with the new instrumentation
     19        points.
     20
     21        * dom/Element.cpp:
     22        (WebCore::Element::didChangeRenderer): Deleted.
     23        * dom/Element.h:
     24        * dom/Node.h:
     25        (WebCore::Node::didChangeRenderer): Deleted.
     26        * inspector/InspectorInstrumentation.cpp:
     27        (WebCore::InspectorInstrumentation::nodeLayoutContextChangedImpl):
     28        * inspector/InspectorInstrumentation.h:
     29        (WebCore::InspectorInstrumentation::nodeLayoutContextChanged):
     30        * inspector/agents/InspectorCSSAgent.cpp:
     31        (WebCore::InspectorCSSAgent::InspectorCSSAgent):
     32        (WebCore::InspectorCSSAgent::reset):
     33        (WebCore::InspectorCSSAgent::nodeLayoutContextTypeChanged):
     34        (WebCore::InspectorCSSAgent::layoutContextTypeChangedTimerFired):
     35        - Moved layout change events behind a timer firing.
     36        * inspector/agents/InspectorCSSAgent.h:
     37        * rendering/RenderGrid.cpp:
     38        (WebCore::RenderGrid::RenderGrid):
     39        (WebCore::RenderGrid::~RenderGrid):
     40        - Move instrumentation from `Node::setRenderer` to `RenderGrid`.
     41        * rendering/RenderObject.h:
     42        (WebCore::Node::setRenderer):
     43
    1442021-03-22  Peng Liu  <peng.liu6@apple.com>
    245
  • trunk/Source/WebCore/dom/Element.cpp

    r274812 r274818  
    45954595}
    45964596
    4597 void Element::didChangeRenderer(RenderObject* oldRenderer)
    4598 {
    4599     InspectorInstrumentation::nodeLayoutContextChanged(*this, oldRenderer);
    4600 }
    4601 
    46024597#if ENABLE(CSS_TYPED_OM)
    46034598
  • trunk/Source/WebCore/dom/Element.h

    r274812 r274818  
    734734    void attachAttributeNodeIfNeeded(Attr&);
    735735   
    736     void didChangeRenderer(RenderObject*) final;
    737 
    738736#if ASSERT_ENABLED
    739737    WEBCORE_EXPORT bool fastAttributeLookupAllowed(const QualifiedName&) const;
  • trunk/Source/WebCore/dom/Node.h

    r274173 r274818  
    711711    void moveNodeToNewDocument(Document& oldDocument, Document& newDocument);
    712712   
    713     virtual void didChangeRenderer(RenderObject*) { };
    714 
    715713    struct NodeRareDataDeleter {
    716714        void operator()(NodeRareData*) const;
  • trunk/Source/WebCore/inspector/InspectorInstrumentation.cpp

    r273865 r274818  
    177177}
    178178
    179 void InspectorInstrumentation::nodeLayoutContextChangedImpl(InstrumentingAgents& instrumentingAgents, Node& node, RenderObject* oldRenderer)
     179void InspectorInstrumentation::nodeLayoutContextChangedImpl(InstrumentingAgents& instrumentingAgents, Node& node, RenderObject* newRenderer)
    180180{
    181181    if (auto* cssAgent = instrumentingAgents.enabledCSSAgent())
    182         cssAgent->nodeLayoutContextTypeChanged(node, oldRenderer);
     182        cssAgent->nodeLayoutContextTypeChanged(node, newRenderer);
    183183}
    184184
  • trunk/Source/WebCore/inspector/InspectorInstrumentation.h

    r273865 r274818  
    602602}
    603603
    604 inline void InspectorInstrumentation::nodeLayoutContextChanged(Node& node, RenderObject* oldRenderer)
     604inline void InspectorInstrumentation::nodeLayoutContextChanged(Node& node, RenderObject* newRenderer)
    605605{
    606606    FAST_RETURN_IF_NO_FRONTENDS(void());
    607607    if (auto* agents = instrumentingAgents(node.document()))
    608         nodeLayoutContextChangedImpl(*agents, node, oldRenderer);
     608        nodeLayoutContextChangedImpl(*agents, node, newRenderer);
    609609}
    610610
  • trunk/Source/WebCore/inspector/agents/InspectorCSSAgent.cpp

    r273821 r274818  
    305305    , m_frontendDispatcher(makeUnique<CSSFrontendDispatcher>(context.frontendRouter))
    306306    , m_backendDispatcher(CSSBackendDispatcher::create(context.backendDispatcher, this))
     307    , m_layoutContextTypeChangedTimer(*this, &InspectorCSSAgent::layoutContextTypeChangedTimerFired)
    307308{
    308309}
     
    327328    m_documentToInspectorStyleSheet.clear();
    328329    m_documentToKnownCSSStyleSheets.clear();
     330    m_nodesWithPendingLayoutContextTypeChanges.clear();
     331    if (m_layoutContextTypeChangedTimer.isActive())
     332        m_layoutContextTypeChangedTimer.stop();
    329333    m_layoutContextTypeChangedMode = Protocol::CSS::LayoutContextTypeChangedMode::Observed;
    330334    resetPseudoStates();
     
    967971}
    968972
    969 void InspectorCSSAgent::nodeLayoutContextTypeChanged(Node& node, RenderObject* oldRenderer)
     973void InspectorCSSAgent::nodeLayoutContextTypeChanged(Node& node, RenderObject* newRenderer)
    970974{
    971975    auto* domAgent = m_instrumentingAgents.persistentDOMAgent();
    972976    if (!domAgent)
    973977        return;
    974    
    975     auto newLayoutContextType = layoutContextTypeForRenderer(node.renderer());
    976     if (newLayoutContextType == layoutContextTypeForRenderer(oldRenderer))
    977         return;
    978    
     978
    979979    auto nodeId = domAgent->boundNodeId(&node);
    980980    if (!nodeId && m_layoutContextTypeChangedMode == Protocol::CSS::LayoutContextTypeChangedMode::All) {
     
    984984    if (!nodeId)
    985985        return;
    986    
    987     m_frontendDispatcher->nodeLayoutContextTypeChanged(nodeId, WTFMove(newLayoutContextType));
     986
     987    m_nodesWithPendingLayoutContextTypeChanges.set(nodeId, layoutContextTypeForRenderer(newRenderer));
     988    if (!m_layoutContextTypeChangedTimer.isActive())
     989        m_layoutContextTypeChangedTimer.startOneShot(0_s);
     990}
     991
     992void InspectorCSSAgent::layoutContextTypeChangedTimerFired()
     993{
     994    for (auto&& [nodeId, layoutContextType] : std::exchange(m_nodesWithPendingLayoutContextTypeChanges, { }))
     995        m_frontendDispatcher->nodeLayoutContextTypeChanged(nodeId, WTFMove(layoutContextType));
    988996}
    989997
  • trunk/Source/WebCore/inspector/agents/InspectorCSSAgent.h

    r272566 r274818  
    3131#include "InspectorWebAgentBase.h"
    3232#include "SecurityContext.h"
     33#include "Timer.h"
    3334#include <JavaScriptCore/InspectorBackendDispatchers.h>
    3435#include <wtf/HashMap.h>
     
    157158    RefPtr<Inspector::Protocol::CSS::CSSStyle> buildObjectForAttributesStyle(StyledElement&);
    158159
     160    void layoutContextTypeChangedTimerFired();
    159161
    160162    void resetPseudoStates();
     
    173175    int m_lastStyleSheetId { 1 };
    174176    bool m_creatingViaInspectorStyleSheet { false };
     177
     178    HashMap<Inspector::Protocol::DOM::NodeId, Optional<Inspector::Protocol::CSS::LayoutContextType>> m_nodesWithPendingLayoutContextTypeChanges;
     179    Timer m_layoutContextTypeChangedTimer;
    175180    Inspector::Protocol::CSS::LayoutContextTypeChangedMode m_layoutContextTypeChangedMode { Inspector::Protocol::CSS::LayoutContextTypeChangedMode::Observed };
    176181};
  • trunk/Source/WebCore/rendering/RenderGrid.cpp

    r274477 r274818  
    3232#include "GridPositionsResolver.h"
    3333#include "GridTrackSizingAlgorithm.h"
     34#include "InspectorInstrumentation.h"
    3435#include "LayoutRepainter.h"
    3536#include "RenderChildIterator.h"
     
    5758    // All of our children must be block level.
    5859    setChildrenInline(false);
    59 }
    60 
    61 RenderGrid::~RenderGrid() = default;
     60
     61    InspectorInstrumentation::nodeLayoutContextChanged(element, this);
     62}
     63
     64RenderGrid::~RenderGrid()
     65{
     66    InspectorInstrumentation::nodeLayoutContextChanged(element(), nullptr);
     67}
    6268
    6369StyleSelfAlignmentData RenderGrid::selfAlignmentForChild(GridAxis axis, const RenderBox& child, const RenderStyle* gridStyle) const
  • trunk/Source/WebCore/rendering/RenderObject.h

    r274287 r274818  
    11511151inline void Node::setRenderer(RenderObject* renderer)
    11521152{
    1153     auto oldRenderer = this->renderer();
    11541153    m_rendererWithStyleFlags.setPointer(renderer);
    1155     didChangeRenderer(oldRenderer);
    11561154}
    11571155
Note: See TracChangeset for help on using the changeset viewer.