From d8109fa9a0aae6ee09eca1d6b5cfab285af318f9 Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Sat, 4 Jan 2020 10:34:36 -0500 Subject: Bug 1309147 - Part 5: Eliminate performance cliff when accessing CEReactions code. Tag UXP Issue #1344 --- dom/base/CustomElementRegistry.cpp | 11 +++++++++-- dom/base/CustomElementRegistry.h | 13 ++++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) (limited to 'dom') diff --git a/dom/base/CustomElementRegistry.cpp b/dom/base/CustomElementRegistry.cpp index b50a1345e..c3d25465e 100644 --- a/dom/base/CustomElementRegistry.cpp +++ b/dom/base/CustomElementRegistry.cpp @@ -905,7 +905,11 @@ CustomElementReactionsStack::PopAndInvokeElementQueue() "Reaction stack shouldn't be empty"); ElementQueue& elementQueue = mReactionsStack.LastElement(); - InvokeReactions(elementQueue); + // Check element queue size in order to reduce function call overhead. + if (!elementQueue.IsEmpty()) { + InvokeReactions(elementQueue); + } + DebugOnly isRemovedElement = mReactionsStack.RemoveElement(elementQueue); MOZ_ASSERT(isRemovedElement, "Reaction stack should have an element queue to remove"); @@ -954,7 +958,10 @@ CustomElementReactionsStack::Enqueue(Element* aElement, void CustomElementReactionsStack::InvokeBackupQueue() { - InvokeReactions(mBackupQueue); + // Check backup queue size in order to reduce function call overhead. + if (!mBackupQueue.IsEmpty()) { + InvokeReactions(mBackupQueue); + } } void diff --git a/dom/base/CustomElementRegistry.h b/dom/base/CustomElementRegistry.h index 5fc2eb2fd..24d501d73 100644 --- a/dom/base/CustomElementRegistry.h +++ b/dom/base/CustomElementRegistry.h @@ -179,7 +179,8 @@ public: // nsWeakPtr is a weak pointer of Element // The element reaction queues are stored in ElementReactionQueueMap. // We need to lookup ElementReactionQueueMap again to get relevant reaction queue. - typedef nsTArray ElementQueue; + // The choice of 1 for the auto size here is based on gut feeling. + typedef AutoTArray ElementQueue; /** * Enqueue a custom element upgrade reaction @@ -201,13 +202,19 @@ public: private: ~CustomElementReactionsStack() {}; - typedef nsTArray> ReactionQueue; + // There is 1 reaction in reaction queue, when 1) it becomes disconnected, + // 2) it’s adopted into a new document, 3) its attributes are changed, + // appended, removed, or replaced. + // There are 3 reactions in reaction queue when doing upgrade operation, + // e.g., create an element, insert a node. + typedef AutoTArray, 3> ReactionQueue; typedef nsClassHashtable ElementReactionQueueMap; ElementReactionQueueMap mElementReactionQueueMap; - nsTArray mReactionsStack; + // The choice of 8 for the auto size here is based on gut feeling. + AutoTArray mReactionsStack; ElementQueue mBackupQueue; // https://html.spec.whatwg.org/#enqueue-an-element-on-the-appropriate-element-queue bool mIsBackupQueueProcessing; -- cgit v1.2.3