Title: [137680] trunk/Source/WebCore
Revision
137680
Author
[email protected]
Date
2012-12-13 16:20:23 -0800 (Thu, 13 Dec 2012)

Log Message

Event dispatch: Avoid heap allocations in ensureEventAncestors() typical case.
<http://webkit.org/b/104938>

Reviewed by Anders Carlsson.

Give the EventTarget and EventContext vectors an inline capacity of 32 (no science here, just a
non-zero number.) As these vectors are created on the stack already, this is merely using a bit
more stack space to avoid malloc()ing all the gosh-darn time.

Looks like ~6% improvement on Dromaeo/jslib-event-prototype.

* dom/EventDispatcher.cpp:
(WebCore::EventRelatedTargetAdjuster::adjust):
(WebCore::EventRelatedTargetAdjuster::findRelatedTarget):
(WebCore::EventDispatcher::ensureEventAncestors):
* dom/EventDispatcher.h:
(EventRelatedTargetAdjuster):
(EventDispatcher):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (137679 => 137680)


--- trunk/Source/WebCore/ChangeLog	2012-12-14 00:20:07 UTC (rev 137679)
+++ trunk/Source/WebCore/ChangeLog	2012-12-14 00:20:23 UTC (rev 137680)
@@ -1,3 +1,24 @@
+2012-12-13  Andreas Kling  <[email protected]>
+
+        Event dispatch: Avoid heap allocations in ensureEventAncestors() typical case.
+        <http://webkit.org/b/104938>
+
+        Reviewed by Anders Carlsson.
+
+        Give the EventTarget and EventContext vectors an inline capacity of 32 (no science here, just a
+        non-zero number.) As these vectors are created on the stack already, this is merely using a bit
+        more stack space to avoid malloc()ing all the gosh-darn time.
+
+        Looks like ~6% improvement on Dromaeo/jslib-event-prototype.
+
+        * dom/EventDispatcher.cpp:
+        (WebCore::EventRelatedTargetAdjuster::adjust):
+        (WebCore::EventRelatedTargetAdjuster::findRelatedTarget):
+        (WebCore::EventDispatcher::ensureEventAncestors):
+        * dom/EventDispatcher.h:
+        (EventRelatedTargetAdjuster):
+        (EventDispatcher):
+
 2012-12-13  James Simonsen  <[email protected]>
 
         [Resource Timing] Don't report resources with data: urls

Modified: trunk/Source/WebCore/dom/EventDispatcher.cpp (137679 => 137680)


--- trunk/Source/WebCore/dom/EventDispatcher.cpp	2012-12-14 00:20:07 UTC (rev 137679)
+++ trunk/Source/WebCore/dom/EventDispatcher.cpp	2012-12-14 00:20:23 UTC (rev 137680)
@@ -60,12 +60,12 @@
     ASSERT(m_relatedTarget);
 }
 
-void EventRelatedTargetAdjuster::adjust(Vector<EventContext>& ancestors)
+void EventRelatedTargetAdjuster::adjust(Vector<EventContext, 32>& ancestors)
 {
     // Synthetic mouse events can have a relatedTarget which is identical to the target.
     bool targetIsIdenticalToToRelatedTarget = (m_node.get() == m_relatedTarget.get());
 
-    Vector<EventTarget*> relatedTargetStack;
+    Vector<EventTarget*, 32> relatedTargetStack;
     TreeScope* lastTreeScope = 0;
     for (AncestorChainWalker walker(m_relatedTarget.get()); walker.get(); walker.parent()) {
         Node* node = walker.get();
@@ -86,7 +86,7 @@
 
     lastTreeScope = 0;
     EventTarget* adjustedRelatedTarget = 0;
-    for (Vector<EventContext>::iterator iter = ancestors.begin(); iter < ancestors.end(); ++iter) {
+    for (Vector<EventContext, 32>::iterator iter = ancestors.begin(); iter < ancestors.end(); ++iter) {
         TreeScope* scope = iter->node()->treeScope();
         if (scope == lastTreeScope) {
             // Re-use the previous adjustedRelatedTarget if treeScope does not change. Just for the performance optimization.
@@ -111,7 +111,7 @@
 
 EventTarget* EventRelatedTargetAdjuster::findRelatedTarget(TreeScope* scope)
 {
-    Vector<TreeScope*> parentTreeScopes;
+    Vector<TreeScope*, 32> parentTreeScopes;
     EventTarget* relatedTarget = 0;
     while (scope) {
         parentTreeScopes.append(scope);
@@ -122,7 +122,7 @@
         }
         scope = scope->parentTreeScope();
     }
-    for (Vector<TreeScope*>::iterator iter = parentTreeScopes.begin(); iter < parentTreeScopes.end(); ++iter)
+    for (Vector<TreeScope*, 32>::iterator iter = parentTreeScopes.begin(); iter < parentTreeScopes.end(); ++iter)
       m_relatedTargetMap.add(*iter, relatedTarget);
     return relatedTarget;
 }
@@ -188,7 +188,7 @@
     m_ancestorsInitialized = true;
     bool inDocument = m_node->inDocument();
     bool isSVGElement = m_node->isSVGElement();
-    Vector<EventTarget*> targetStack;
+    Vector<EventTarget*, 32> targetStack;
     for (AncestorChainWalker walker(m_node.get()); walker.get(); walker.parent()) {
         Node* node = walker.get();
         if (targetStack.isEmpty())

Modified: trunk/Source/WebCore/dom/EventDispatcher.h (137679 => 137680)


--- trunk/Source/WebCore/dom/EventDispatcher.h	2012-12-14 00:20:07 UTC (rev 137679)
+++ trunk/Source/WebCore/dom/EventDispatcher.h	2012-12-14 00:20:23 UTC (rev 137680)
@@ -26,6 +26,7 @@
 #ifndef EventDispatcher_h
 #define EventDispatcher_h
 
+#include "EventContext.h"
 #include "SimulatedClickOptions.h"
 #include <wtf/Forward.h>
 #include <wtf/HashMap.h>
@@ -34,7 +35,6 @@
 namespace WebCore {
 
 class Event;
-class EventContext;
 class EventDispatchMediator;
 class EventTarget;
 class FrameView;
@@ -58,7 +58,7 @@
 class EventRelatedTargetAdjuster {
 public:
     EventRelatedTargetAdjuster(PassRefPtr<Node>, PassRefPtr<Node> relatedTarget);
-    void adjust(Vector<EventContext>&);
+    void adjust(Vector<EventContext, 32>&);
 private:
     typedef HashMap<TreeScope*, EventTarget*> RelatedTargetMap;
     EventTarget* findRelatedTarget(TreeScope*);
@@ -93,7 +93,7 @@
     EventDispatchContinuation dispatchEventAtBubbling(PassRefPtr<Event>, WindowEventContext&);
     void dispatchEventPostProcess(PassRefPtr<Event>, void* preDispatchEventHandlerResult);
 
-    Vector<EventContext> m_ancestors;
+    Vector<EventContext, 32> m_ancestors;
     RefPtr<Node> m_node;
     RefPtr<FrameView> m_view;
     bool m_ancestorsInitialized;
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to