Changeset 144407 in webkit


Ignore:
Timestamp:
Feb 28, 2013 6:12:54 PM (11 years ago)
Author:
abarth@webkit.org
Message:

The threaded HTML parser shouldn't need to invalidate the speculation buffer on every document.write
https://bugs.webkit.org/show_bug.cgi?id=111130

Reviewed by Eric Seidel.

Previously, the threaded HTML parser always invalidated its speculation
buffer when it received a document.write. That means we performed
poorly on web sites that contained document.write calls early in the
page.

This patch teaches the HTMLDocumentParser that we don't need to discard
the speculation buffer in the common case of starting and ending in the
DataState.

  • html/parser/BackgroundHTMLParser.cpp:

(WebCore::BackgroundHTMLParser::sendTokensToMainThread):

  • html/parser/HTMLDocumentParser.cpp:

(WebCore::HTMLDocumentParser::checkForSpeculationFailure):
(WebCore::HTMLDocumentParser::didFailSpeculation):

  • html/parser/HTMLDocumentParser.h:

(WebCore):
(ParsedChunk):

Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r144405 r144407  
     12013-02-28  Adam Barth  <abarth@webkit.org>
     2
     3        The threaded HTML parser shouldn't need to invalidate the speculation buffer on every document.write
     4        https://bugs.webkit.org/show_bug.cgi?id=111130
     5
     6        Reviewed by Eric Seidel.
     7
     8        Previously, the threaded HTML parser always invalidated its speculation
     9        buffer when it received a document.write.  That means we performed
     10        poorly on web sites that contained document.write calls early in the
     11        page.
     12
     13        This patch teaches the HTMLDocumentParser that we don't need to discard
     14        the speculation buffer in the common case of starting and ending in the
     15        DataState.
     16
     17        * html/parser/BackgroundHTMLParser.cpp:
     18        (WebCore::BackgroundHTMLParser::sendTokensToMainThread):
     19        * html/parser/HTMLDocumentParser.cpp:
     20        (WebCore::HTMLDocumentParser::checkForSpeculationFailure):
     21        (WebCore::HTMLDocumentParser::didFailSpeculation):
     22        * html/parser/HTMLDocumentParser.h:
     23        (WebCore):
     24        (ParsedChunk):
     25
    1262013-02-28  Eberhard Graether  <egraether@google.com>
    227
  • trunk/Source/WebCore/html/parser/BackgroundHTMLParser.cpp

    r144010 r144407  
    280280    chunk->tokens = m_pendingTokens.release();
    281281    chunk->preloads.swap(m_pendingPreloads);
     282    chunk->tokenizerState = m_tokenizer->state();
    282283    chunk->inputCheckpoint = m_input.createCheckpoint();
    283284    chunk->preloadScannerCheckpoint = m_preloadScanner->createCheckpoint();
  • trunk/Source/WebCore/html/parser/HTMLDocumentParser.cpp

    r144158 r144407  
    333333    if (!m_tokenizer)
    334334        return;
    335     // FIXME: If the tokenizer is in the same state as when we started this function,
    336     // then we haven't necessarily failed our speculation.
     335    if (!m_currentChunk)
     336        return;
     337    // Currently we're only smart enough to reuse the speculation buffer if the tokenizer
     338    // both starts and ends in the DataState. That state is simplest because the HTMLToken
     339    // is always in the Uninitialized state. We should consider whether we can reuse the
     340    // speculation buffer in other states, but we'd likely need to do something more
     341    // sophisticated with the HTMLToken.
     342    if (m_currentChunk->tokenizerState == HTMLTokenizer::DataState && m_tokenizer->state() == HTMLTokenizer::DataState && m_input.current().isEmpty()) {
     343        ASSERT(m_token->isUninitialized());
     344        m_tokenizer.clear();
     345        m_token.clear();
     346        return;
     347    }
    337348    didFailSpeculation(m_token.release(), m_tokenizer.release());
    338349}
     
    340351void HTMLDocumentParser::didFailSpeculation(PassOwnPtr<HTMLToken> token, PassOwnPtr<HTMLTokenizer> tokenizer)
    341352{
    342     if (!m_currentChunk)
    343         return;
    344 
    345353    m_weakFactory.revokeAll();
    346354    m_speculations.clear();
  • trunk/Source/WebCore/html/parser/HTMLDocumentParser.h

    r144000 r144407  
    3737#include "HTMLSourceTracker.h"
    3838#include "HTMLToken.h"
     39#include "HTMLTokenizer.h"
    3940#include "ScriptableDocumentParser.h"
    4041#include "SegmentedString.h"
     
    5556class HTMLDocument;
    5657class HTMLParserScheduler;
    57 class HTMLTokenizer;
    5858class HTMLScriptRunner;
    5959class HTMLTreeBuilder;
     
    9090        OwnPtr<CompactHTMLTokenStream> tokens;
    9191        PreloadRequestStream preloads;
     92        HTMLTokenizer::State tokenizerState;
    9293        HTMLInputCheckpoint inputCheckpoint;
    9394        TokenPreloadScannerCheckpoint preloadScannerCheckpoint;
Note: See TracChangeset for help on using the changeset viewer.