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

Changeset 280901 in webkit


Ignore:
Timestamp:
Aug 11, 2021, 3:43:19 AM (5 years ago)
Author:
Adrian Perez de Castro
Message:

Merge r274818 - 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:
releases/WebKitGTK/webkit-2.32/Source/WebCore
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • releases/WebKitGTK/webkit-2.32/Source/WebCore/ChangeLog

    r280900 r280901  
     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  Chris Dumez  <cdumez@apple.com>
    245
  • releases/WebKitGTK/webkit-2.32/Source/WebCore/dom/Element.cpp

    r280232 r280901  
    45654565}
    45664566
    4567 void Element::didChangeRenderer(RenderObject* oldRenderer)
    4568 {
    4569     InspectorInstrumentation::nodeLayoutContextChanged(*this, oldRenderer);
    4570 }
    4571 
    45724567#if ENABLE(CSS_TYPED_OM)
    45734568
  • releases/WebKitGTK/webkit-2.32/Source/WebCore/dom/Element.h

    r272433 r280901  
    729729    void attachAttributeNodeIfNeeded(Attr&);
    730730   
    731     void didChangeRenderer(RenderObject*) final;
    732 
    733731#if ASSERT_ENABLED
    734732    WEBCORE_EXPORT bool fastAttributeLookupAllowed(const QualifiedName&) const;
  • releases/WebKitGTK/webkit-2.32/Source/WebCore/dom/Node.h

    r280829 r280901  
    730730    void moveNodeToNewDocument(Document& oldDocument, Document& newDocument);
    731731   
    732     virtual void didChangeRenderer(RenderObject*) { };
    733 
    734732    struct NodeRareDataDeleter {
    735733        void operator()(NodeRareData*) const;
  • releases/WebKitGTK/webkit-2.32/Source/WebCore/inspector/InspectorInstrumentation.cpp

    r272433 r280901  
    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
  • releases/WebKitGTK/webkit-2.32/Source/WebCore/inspector/InspectorInstrumentation.h

    r272433 r280901  
    605605}
    606606
    607 inline void InspectorInstrumentation::nodeLayoutContextChanged(Node& node, RenderObject* oldRenderer)
     607inline void InspectorInstrumentation::nodeLayoutContextChanged(Node& node, RenderObject* newRenderer)
    608608{
    609609    FAST_RETURN_IF_NO_FRONTENDS(void());
    610610    if (auto* agents = instrumentingAgents(node.document()))
    611         nodeLayoutContextChangedImpl(*agents, node, oldRenderer);
     611        nodeLayoutContextChangedImpl(*agents, node, newRenderer);
    612612}
    613613
  • releases/WebKitGTK/webkit-2.32/Source/WebCore/inspector/agents/InspectorCSSAgent.cpp

    r273502 r280901  
    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();
     
    964968}
    965969
    966 void InspectorCSSAgent::nodeLayoutContextTypeChanged(Node& node, RenderObject* oldRenderer)
     970void InspectorCSSAgent::nodeLayoutContextTypeChanged(Node& node, RenderObject* newRenderer)
    967971{
    968972    auto* domAgent = m_instrumentingAgents.persistentDOMAgent();
    969973    if (!domAgent)
    970974        return;
    971    
    972     auto newLayoutContextType = layoutContextTypeForRenderer(node.renderer());
    973     if (newLayoutContextType == layoutContextTypeForRenderer(oldRenderer))
    974         return;
    975    
     975
    976976    auto nodeId = domAgent->boundNodeId(&node);
    977977    if (!nodeId && m_layoutContextTypeChangedMode == Protocol::CSS::LayoutContextTypeChangedMode::All) {
     
    981981    if (!nodeId)
    982982        return;
    983    
    984     m_frontendDispatcher->nodeLayoutContextTypeChanged(nodeId, WTFMove(newLayoutContextType));
     983
     984    m_nodesWithPendingLayoutContextTypeChanges.set(nodeId, layoutContextTypeForRenderer(newRenderer));
     985    if (!m_layoutContextTypeChangedTimer.isActive())
     986        m_layoutContextTypeChangedTimer.startOneShot(0_s);
     987}
     988
     989void InspectorCSSAgent::layoutContextTypeChangedTimerFired()
     990{
     991    for (auto&& [nodeId, layoutContextType] : std::exchange(m_nodesWithPendingLayoutContextTypeChanges, { }))
     992        m_frontendDispatcher->nodeLayoutContextTypeChanged(nodeId, WTFMove(layoutContextType));
    985993}
    986994
  • releases/WebKitGTK/webkit-2.32/Source/WebCore/inspector/agents/InspectorCSSAgent.h

    r272566 r280901  
    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};
  • releases/WebKitGTK/webkit-2.32/Source/WebCore/rendering/RenderGrid.cpp

    r273492 r280901  
    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
  • releases/WebKitGTK/webkit-2.32/Source/WebCore/rendering/RenderObject.h

    r273290 r280901  
    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.