Title: [143845] trunk/Source/WebCore
Revision
143845
Author
aba...@webkit.org
Date
2013-02-23 10:37:50 -0800 (Sat, 23 Feb 2013)

Log Message

Threaded HTML parser should pass fast/parser/parser-yield-timing.html
https://bugs.webkit.org/show_bug.cgi?id=110647

Reviewed by Eric Seidel.

Previously, the threaded HTML parser would run for an arbitrary amount
of time without yielding after speculation succeeded. This might be the
cause of the good DOMContentLoaded numbers.

Note: This patch also demonstrates that the ParseHTML_max numbers
aren't correct currently because they're measuring the interior of this
loop instead of all the time spent in the loop. We should move the
instrumentation in a followup patch.

 * html/parser/HTMLDocumentParser.cpp:
(WebCore::HTMLDocumentParser::resumeParsingAfterYield):
(WebCore::HTMLDocumentParser::pumpPendingSpeculations):
(WebCore):
(WebCore::HTMLDocumentParser::resumeParsingAfterScriptExecution):
* html/parser/HTMLDocumentParser.h:
(HTMLDocumentParser):
* html/parser/HTMLParserScheduler.cpp:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (143844 => 143845)


--- trunk/Source/WebCore/ChangeLog	2013-02-23 18:22:35 UTC (rev 143844)
+++ trunk/Source/WebCore/ChangeLog	2013-02-23 18:37:50 UTC (rev 143845)
@@ -1,3 +1,28 @@
+2013-02-23  Adam Barth  <aba...@webkit.org>
+
+        Threaded HTML parser should pass fast/parser/parser-yield-timing.html
+        https://bugs.webkit.org/show_bug.cgi?id=110647
+
+        Reviewed by Eric Seidel.
+
+        Previously, the threaded HTML parser would run for an arbitrary amount
+        of time without yielding after speculation succeeded. This might be the
+        cause of the good DOMContentLoaded numbers.
+
+        Note: This patch also demonstrates that the ParseHTML_max numbers
+        aren't correct currently because they're measuring the interior of this
+        loop instead of all the time spent in the loop. We should move the
+        instrumentation in a followup patch.
+
+         * html/parser/HTMLDocumentParser.cpp:
+        (WebCore::HTMLDocumentParser::resumeParsingAfterYield):
+        (WebCore::HTMLDocumentParser::pumpPendingSpeculations):
+        (WebCore):
+        (WebCore::HTMLDocumentParser::resumeParsingAfterScriptExecution):
+        * html/parser/HTMLDocumentParser.h:
+        (HTMLDocumentParser):
+        * html/parser/HTMLParserScheduler.cpp:
+
 2013-02-23  Martin Robinson  <mrobin...@igalia.com>
 
         [GTK] Allow sharing the WebCore include list with the Chromium build

Modified: trunk/Source/WebCore/html/parser/HTMLDocumentParser.cpp (143844 => 143845)


--- trunk/Source/WebCore/html/parser/HTMLDocumentParser.cpp	2013-02-23 18:22:35 UTC (rev 143844)
+++ trunk/Source/WebCore/html/parser/HTMLDocumentParser.cpp	2013-02-23 18:37:50 UTC (rev 143845)
@@ -240,12 +240,17 @@
 // Used by HTMLParserScheduler
 void HTMLDocumentParser::resumeParsingAfterYield()
 {
-    ASSERT(!m_haveBackgroundParser);
-
     // pumpTokenizer can cause this parser to be detached from the Document,
     // but we need to ensure it isn't deleted yet.
     RefPtr<HTMLDocumentParser> protect(this);
 
+#if ENABLE(THREADED_HTML_PARSER)
+    if (m_haveBackgroundParser) {
+        pumpPendingSpeculations();
+        return;
+    }
+#endif
+
     // We should never be here unless we can pump immediately.  Call pumpTokenizer()
     // directly so that ASSERTS will fire if we're wrong.
     pumpTokenizer(AllowYield);
@@ -355,6 +360,8 @@
 
 void HTMLDocumentParser::processParsedChunkFromBackgroundParser(PassOwnPtr<ParsedChunk> chunk)
 {
+    // ASSERT that this object is both attached to the Document and protected.
+    ASSERT(refCount() >= 2);
     ASSERT(shouldUseThreading());
 
     ActiveParserSession session(contextForParsingSession());
@@ -394,6 +401,34 @@
     checkForSpeculationFailure();
 }
 
+void HTMLDocumentParser::pumpPendingSpeculations()
+{
+    // FIXME: Share this constant with the parser scheduler.
+    const double parserTimeLimit = 0.500;
+
+    // ASSERT that this object is both attached to the Document and protected.
+    ASSERT(refCount() >= 2);
+
+    // FIXME: Pass in current input length.
+    InspectorInstrumentationCookie cookie = InspectorInstrumentation::willWriteHTML(document(), 0, lineNumber().zeroBasedInt());
+
+    double startTime = currentTime();
+
+    while (!m_speculations.isEmpty()) {
+        processParsedChunkFromBackgroundParser(m_speculations.takeFirst());
+
+        if (isWaitingForScripts() || isStopped())
+            break;
+
+        if (currentTime() - startTime > parserTimeLimit && !m_speculations.isEmpty()) {
+            m_parserScheduler->scheduleForResume();
+            break;
+        }
+    }
+
+    InspectorInstrumentation::didWriteHTML(cookie, lineNumber().zeroBasedInt());
+}
+
 #endif // ENABLE(THREADED_HTML_PARSER)
 
 void HTMLDocumentParser::forcePlaintextForTextDocument()
@@ -795,18 +830,7 @@
         // processParsedChunkFromBackgroundParser can cause this parser to be detached from the Document,
         // but we need to ensure it isn't deleted yet.
         RefPtr<HTMLDocumentParser> protect(this);
-
-        // FIXME: Pass in current input length.
-        InspectorInstrumentationCookie cookie = InspectorInstrumentation::willWriteHTML(document(), 0, lineNumber().zeroBasedInt());
-
-        while (!m_speculations.isEmpty()) {
-            processParsedChunkFromBackgroundParser(m_speculations.takeFirst());
-            if (isWaitingForScripts() || isStopped())
-                break;
-        }
-
-        InspectorInstrumentation::didWriteHTML(cookie, lineNumber().zeroBasedInt());
-
+        pumpPendingSpeculations();
         return;
     }
 #endif

Modified: trunk/Source/WebCore/html/parser/HTMLDocumentParser.h (143844 => 143845)


--- trunk/Source/WebCore/html/parser/HTMLDocumentParser.h	2013-02-23 18:22:35 UTC (rev 143844)
+++ trunk/Source/WebCore/html/parser/HTMLDocumentParser.h	2013-02-23 18:37:50 UTC (rev 143845)
@@ -142,6 +142,7 @@
     void checkForSpeculationFailure();
     void didFailSpeculation(PassOwnPtr<HTMLToken>, PassOwnPtr<HTMLTokenizer>);
     void processParsedChunkFromBackgroundParser(PassOwnPtr<ParsedChunk>);
+    void pumpPendingSpeculations();
 #endif
 
     Document* contextForParsingSession();

Modified: trunk/Source/WebCore/html/parser/HTMLParserScheduler.cpp (143844 => 143845)


--- trunk/Source/WebCore/html/parser/HTMLParserScheduler.cpp	2013-02-23 18:22:35 UTC (rev 143844)
+++ trunk/Source/WebCore/html/parser/HTMLParserScheduler.cpp	2013-02-23 18:37:50 UTC (rev 143845)
@@ -37,7 +37,7 @@
 static const int defaultParserChunkSize = 4096;
 
 // defaultParserTimeLimit is the seconds the parser will run in one write() call
-// before yielding.  Inline <script> execution can cause it to excede the limit.
+// before yielding. Inline <script> execution can cause it to exceed the limit.
 // FIXME: We would like this value to be 0.2.
 static const double defaultParserTimeLimit = 0.500;
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to