Optimize content extensions interpreting speed.
authorachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 7 Apr 2015 21:17:36 +0000 (21:17 +0000)
committerachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 7 Apr 2015 21:17:36 +0000 (21:17 +0000)
https://bugs.webkit.org/show_bug.cgi?id=143490

Reviewed by Brady Eidson.

* contentextensions/ContentExtensionCompiler.cpp:
(WebCore::ContentExtensions::compileRuleList):
* contentextensions/ContentExtensionsBackend.cpp:
(WebCore::ContentExtensions::ContentExtensionsBackend::actionsForResourceLoad):
Measure total time added by content extensions.
* contentextensions/DFABytecodeCompiler.cpp:
(WebCore::ContentExtensions::DFABytecodeCompiler::compileNode):
(WebCore::ContentExtensions::DFABytecodeCompiler::compile):
When jumping to the root, don't re-add all the actions.
* contentextensions/DFABytecodeCompiler.h:
* platform/URL.cpp:
(WebCore::URL::init):
* platform/URL.h:
(WebCore::URL::protocolIsJavaScript): Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@182492 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/contentextensions/ContentExtensionCompiler.cpp
Source/WebCore/contentextensions/ContentExtensionsBackend.cpp
Source/WebCore/contentextensions/DFABytecodeCompiler.cpp
Source/WebCore/contentextensions/DFABytecodeCompiler.h
Source/WebCore/platform/URL.cpp
Source/WebCore/platform/URL.h

index 75bc816..fd9491d 100644 (file)
@@ -1,3 +1,25 @@
+2015-04-07  Alex Christensen  <achristensen@webkit.org>
+
+        Optimize content extensions interpreting speed.
+        https://bugs.webkit.org/show_bug.cgi?id=143490
+
+        Reviewed by Brady Eidson.
+
+        * contentextensions/ContentExtensionCompiler.cpp:
+        (WebCore::ContentExtensions::compileRuleList):
+        * contentextensions/ContentExtensionsBackend.cpp:
+        (WebCore::ContentExtensions::ContentExtensionsBackend::actionsForResourceLoad):
+        Measure total time added by content extensions.
+        * contentextensions/DFABytecodeCompiler.cpp:
+        (WebCore::ContentExtensions::DFABytecodeCompiler::compileNode):
+        (WebCore::ContentExtensions::DFABytecodeCompiler::compile):
+        When jumping to the root, don't re-add all the actions.
+        * contentextensions/DFABytecodeCompiler.h:
+        * platform/URL.cpp:
+        (WebCore::URL::init):
+        * platform/URL.h:
+        (WebCore::URL::protocolIsJavaScript): Added.
+
 2015-04-07  Simon Fraser  <simon.fraser@apple.com>
 
         Add a new setting, AntialiasedFontDilationEnabled, exposed via WK2.
index 6c0ad8e..83c0b09 100644 (file)
@@ -213,6 +213,8 @@ std::error_code compileRuleList(ContentExtensionCompilationClient& client, const
 #if CONTENT_EXTENSIONS_PERFORMANCE_REPORTING
     double dfaBuildTimeEnd = monotonicallyIncreasingTime();
     dataLogF("    Time spent building and compiling the DFAs: %f\n", (dfaBuildTimeEnd - dfaBuildTimeStart));
+    dataLogF("    Bytecode size %zu\n", bytecode.size());
+    dataLogF("    DFA count %zu\n", nfas.size());
 #endif
 
     client.writeBytecode(WTF::move(bytecode));
index ad16740..1ed76b7 100644 (file)
@@ -30,6 +30,7 @@
 
 #include "CompiledContentExtension.h"
 #include "ContentExtension.h"
+#include "ContentExtensionsDebugging.h"
 #include "DFABytecodeInterpreter.h"
 #include "Document.h"
 #include "DocumentLoader.h"
@@ -72,6 +73,13 @@ void ContentExtensionsBackend::removeAllContentExtensions()
 
 Vector<Action> ContentExtensionsBackend::actionsForResourceLoad(const ResourceLoadInfo& resourceLoadInfo) const
 {
+#if CONTENT_EXTENSIONS_PERFORMANCE_REPORTING
+    double addedTimeStart = monotonicallyIncreasingTime();
+#endif
+    if (resourceLoadInfo.resourceURL.protocolIsData()
+        || resourceLoadInfo.resourceURL.protocolIsJavaScript())
+        return Vector<Action>();
+
     const String& urlString = resourceLoadInfo.resourceURL.string();
     ASSERT_WITH_MESSAGE(urlString.containsOnlyASCII(), "A decoded URL should only contain ASCII characters. The matching algorithm assumes the input is ASCII.");
     const CString& urlCString = urlString.utf8();
@@ -117,6 +125,10 @@ Vector<Action> ContentExtensionsBackend::actionsForResourceLoad(const ResourceLo
             finalActions.append(Action(ActionType::CSSDisplayNoneStyleSheet, contentExtension->identifier()));
         }
     }
+#if CONTENT_EXTENSIONS_PERFORMANCE_REPORTING
+    double addedTimeEnd = monotonicallyIncreasingTime();
+    WTFLogAlways("Time added: %f microseconds %s", (addedTimeEnd - addedTimeStart) * 1.0e6, resourceLoadInfo.resourceURL.string().utf8().data());
+#endif
     return finalActions;
 }
 
index 2434afb..a235898 100644 (file)
@@ -93,12 +93,13 @@ void DFABytecodeCompiler::emitTerminate()
     append<DFABytecodeInstruction>(m_bytecode, DFABytecodeInstruction::Terminate);
 }
 
-void DFABytecodeCompiler::compileNode(unsigned index)
+void DFABytecodeCompiler::compileNode(unsigned index, bool root)
 {
     const DFANode& node = m_dfa.nodeAt(index);
 
     // Record starting index for linking.
-    m_nodeStartOffsets[index] = m_bytecode.size();
+    if (!root)
+        m_nodeStartOffsets[index] = m_bytecode.size();
 
     for (uint64_t action : node.actions) {
         // High bits are used to store flags. See compileRuleList.
@@ -107,6 +108,12 @@ void DFABytecodeCompiler::compileNode(unsigned index)
         else
             emitAppendAction(static_cast<unsigned>(action));
     }
+    
+    // If we jump to the root, we don't want to re-add its actions to a HashSet.
+    // We know we have already added them because the root is always compiled first and we always start interpreting at the beginning.
+    if (root)
+        m_nodeStartOffsets[index] = m_bytecode.size();
+    
     compileNodeTransitions(node);
 }
 
@@ -200,10 +207,10 @@ void DFABytecodeCompiler::compile()
     m_nodeStartOffsets.resize(m_dfa.size());
     
     // Make sure the root is always at the beginning of the bytecode.
-    compileNode(m_dfa.root());
+    compileNode(m_dfa.root(), true);
     for (unsigned i = 0; i < m_dfa.size(); i++) {
         if (i != m_dfa.root())
-            compileNode(i);
+            compileNode(i, false);
     }
 
     // Link.
index 1a56e5a..bb811c3 100644 (file)
@@ -62,7 +62,7 @@ private:
         unsigned destination;
         bool caseSensitive;
     };
-    void compileNode(unsigned);
+    void compileNode(unsigned, bool root);
     void compileNodeTransitions(const DFANode&);
     void compileCheckForRange(const Range&);
 
index d19e38e..1d1199c 100644 (file)
@@ -470,7 +470,7 @@ void URL::init(const URL& base, const String& relative, const TextEncoding& enco
     // For compatibility with Win IE, treat backslashes as if they were slashes,
     // as long as we're not dealing with javascript: or data: URLs.
     String rel = relative;
-    if (rel.contains('\\') && !(protocolIsJavaScript(rel) || protocolIs(rel, "data")))
+    if (rel.contains('\\') && !(WebCore::protocolIsJavaScript(rel) || protocolIs(rel, "data")))
         rel = substituteBackslashes(rel);
 
     bool allASCII = rel.containsOnlyASCII();
index a638d78..1b92c70 100644 (file)
@@ -127,6 +127,7 @@ public:
     // terminated ASCII argument. The argument must be lower-case.
     WEBCORE_EXPORT bool protocolIs(const char*) const;
     bool protocolIsData() const { return protocolIs("data"); }
+    bool protocolIsJavaScript() const { return protocolIs("javascript"); }
     bool protocolIsInHTTPFamily() const;
     WEBCORE_EXPORT bool isLocalFile() const;
     bool isBlankURL() const;