Changeset 144498 in webkit


Ignore:
Timestamp:
Mar 1, 2013 1:53:26 PM (11 years ago)
Author:
eric@webkit.org
Message:

Threaded HTML Parser has an extra copy of every byte from the network
https://bugs.webkit.org/show_bug.cgi?id=111135

Reviewed by Adam Barth.

Source/WebCore:

Every LayoutTest executes this code in threaded parsing mode.

  • dom/DecodedDataDocumentParser.cpp:

(WebCore::DecodedDataDocumentParser::appendBytes):

  • Pass ownership of the decoded string to the parser.

(WebCore::DecodedDataDocumentParser::flush):

  • Same.
  • dom/DecodedDataDocumentParser.h:

(DecodedDataDocumentParser):

  • dom/Document.cpp:

(WebCore::Document::setContent):

  • dom/DocumentParser.h:

(DocumentParser):

  • dom/RawDataDocumentParser.h:

(WebCore::RawDataDocumentParser::append):

  • html/FTPDirectoryDocument.cpp:

(FTPDirectoryDocumentParser):
(WebCore::FTPDirectoryDocumentParser::append):

  • html/parser/HTMLDocumentParser.cpp:

(WebCore::HTMLDocumentParser::append):

  • html/parser/HTMLDocumentParser.h:

(HTMLDocumentParser):

  • html/parser/HTMLViewSourceParser.cpp:

(WebCore::HTMLViewSourceParser::append):

  • html/parser/HTMLViewSourceParser.h:

(HTMLViewSourceParser):

  • html/parser/TextDocumentParser.cpp:

(WebCore::TextDocumentParser::append):

  • html/parser/TextDocumentParser.h:

(TextDocumentParser):

  • loader/DocumentWriter.cpp:

(WebCore::DocumentWriter::replaceDocument):

  • xml/parser/XMLDocumentParser.cpp:

(WebCore::XMLDocumentParser::append):

  • xml/parser/XMLDocumentParser.h:

(XMLDocumentParser):

  • xml/parser/XMLDocumentParserLibxml2.cpp:

(WebCore::XMLDocumentParser::resumeParsing):

Source/WTF:

The threaded html parser needs to accept ownership
of a string buffer. The easiest way to do this seemed
to be to use a PassRefPtr<StringImpl>, but there was no way
to generated one from a String (easily), so I added one.

  • wtf/text/WTFString.h:

(WTF::String::releaseImpl):

Location:
trunk/Source
Files:
19 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r144346 r144498  
     12013-03-01  Eric Seidel  <eric@webkit.org>
     2
     3        Threaded HTML Parser has an extra copy of every byte from the network
     4        https://bugs.webkit.org/show_bug.cgi?id=111135
     5
     6        Reviewed by Adam Barth.
     7
     8        The threaded html parser needs to accept ownership
     9        of a string buffer.  The easiest way to do this seemed
     10        to be to use a PassRefPtr<StringImpl>, but there was no way
     11        to generated one from a String (easily), so I added one.
     12
     13        * wtf/text/WTFString.h:
     14        (WTF::String::releaseImpl):
     15
    1162013-02-28  Oliver Hunt  <oliver@apple.com>
    217
  • trunk/Source/WTF/wtf/text/WTFString.h

    r142894 r144498  
    168168
    169169    StringImpl* impl() const { return m_impl.get(); }
     170    PassRefPtr<StringImpl> releaseImpl() { return m_impl.release(); }
    170171
    171172    unsigned length() const
  • trunk/Source/WebCore/ChangeLog

    r144497 r144498  
     12013-03-01  Eric Seidel  <eric@webkit.org>
     2
     3        Threaded HTML Parser has an extra copy of every byte from the network
     4        https://bugs.webkit.org/show_bug.cgi?id=111135
     5
     6        Reviewed by Adam Barth.
     7
     8        Every LayoutTest executes this code in threaded parsing mode.
     9
     10        * dom/DecodedDataDocumentParser.cpp:
     11        (WebCore::DecodedDataDocumentParser::appendBytes):
     12         - Pass ownership of the decoded string to the parser.
     13        (WebCore::DecodedDataDocumentParser::flush):
     14         - Same.
     15        * dom/DecodedDataDocumentParser.h:
     16        (DecodedDataDocumentParser):
     17        * dom/Document.cpp:
     18        (WebCore::Document::setContent):
     19        * dom/DocumentParser.h:
     20        (DocumentParser):
     21        * dom/RawDataDocumentParser.h:
     22        (WebCore::RawDataDocumentParser::append):
     23        * html/FTPDirectoryDocument.cpp:
     24        (FTPDirectoryDocumentParser):
     25        (WebCore::FTPDirectoryDocumentParser::append):
     26        * html/parser/HTMLDocumentParser.cpp:
     27        (WebCore::HTMLDocumentParser::append):
     28        * html/parser/HTMLDocumentParser.h:
     29        (HTMLDocumentParser):
     30        * html/parser/HTMLViewSourceParser.cpp:
     31        (WebCore::HTMLViewSourceParser::append):
     32        * html/parser/HTMLViewSourceParser.h:
     33        (HTMLViewSourceParser):
     34        * html/parser/TextDocumentParser.cpp:
     35        (WebCore::TextDocumentParser::append):
     36        * html/parser/TextDocumentParser.h:
     37        (TextDocumentParser):
     38        * loader/DocumentWriter.cpp:
     39        (WebCore::DocumentWriter::replaceDocument):
     40        * xml/parser/XMLDocumentParser.cpp:
     41        (WebCore::XMLDocumentParser::append):
     42        * xml/parser/XMLDocumentParser.h:
     43        (XMLDocumentParser):
     44        * xml/parser/XMLDocumentParserLibxml2.cpp:
     45        (WebCore::XMLDocumentParser::resumeParsing):
     46
    1472013-03-01  David Hyatt  <hyatt@apple.com>
    248
  • trunk/Source/WebCore/dom/DecodedDataDocumentParser.cpp

    r95901 r144498  
    4848
    4949    writer->reportDataReceived();
    50     append(decoded);
     50    append(decoded.releaseImpl());
    5151}
    5252
     
    5858
    5959    writer->reportDataReceived();
    60     append(remainingData);
     60    append(remainingData.releaseImpl());
    6161}
    6262
  • trunk/Source/WebCore/dom/DecodedDataDocumentParser.h

    r95901 r144498  
    4242private:
    4343    // append is used by DocumentWriter::replaceDocument.
    44     virtual void append(const SegmentedString&) = 0;
     44    virtual void append(PassRefPtr<StringImpl>) = 0;
    4545
    4646    // appendBytes and flush are used by DocumentWriter (the loader).
  • trunk/Source/WebCore/dom/Document.cpp

    r144413 r144498  
    13591359{
    13601360    open();
    1361     m_parser->append(content);
     1361    // FIXME: This should probably use insert(), but that's (intentionally)
     1362    // not implemented for the XML parser as it's normally synonymous with
     1363    // document.write(). append() will end up yielding, but close() will
     1364    // pump the tokenizer syncrhonously and finish the parse.
     1365    m_parser->pinToMainThread();
     1366    m_parser->append(content.impl());
    13621367    close();
    13631368}
  • trunk/Source/WebCore/dom/DocumentParser.h

    r144000 r144498  
    2525#define DocumentParser_h
    2626
     27#include <wtf/Forward.h>
    2728#include <wtf/RefCounted.h>
    2829
     
    5253    virtual void pinToMainThread() { }
    5354
    54     // FIXME: append() should be private, but DocumentWriter::replaceDocument
    55     // uses it for now.
    56     virtual void append(const SegmentedString&) = 0;
     55    // FIXME: append() should be private, but DocumentWriter::replaceDocument uses it for now.
     56    // FIXME: This really should take a PassOwnPtr to signify that it expects to take
     57    // ownership of the buffer. The parser expects the PassRefPtr to hold the only ref of the StringImpl.
     58    virtual void append(PassRefPtr<StringImpl>) = 0;
    5759
    5860    virtual void finish() = 0;
  • trunk/Source/WebCore/dom/RawDataDocumentParser.h

    r140036 r144498  
    5757    }
    5858
    59     virtual void append(const SegmentedString&)
     59    virtual void append(PassRefPtr<StringImpl>)
    6060    {
    6161        ASSERT_NOT_REACHED();
  • trunk/Source/WebCore/html/FTPDirectoryDocument.cpp

    r142271 r144498  
    5858    }
    5959
    60     virtual void append(const SegmentedString&);
     60    virtual void append(PassRefPtr<StringImpl>);
    6161    virtual void finish();
    6262
     
    347347}
    348348
    349 void FTPDirectoryDocumentParser::append(const SegmentedString& source)
    350 {
     349void FTPDirectoryDocumentParser::append(PassRefPtr<StringImpl> inputSource)
     350{
     351    String source(inputSource);
     352
    351353    // Make sure we have the table element to append to by loading the template set in the pref, or
    352354    // creating a very basic document with the appropriate table
  • trunk/Source/WebCore/html/parser/HTMLDocumentParser.cpp

    r144407 r144498  
    655655#endif
    656656
    657 void HTMLDocumentParser::append(const SegmentedString& source)
     657void HTMLDocumentParser::append(PassRefPtr<StringImpl> inputSource)
    658658{
    659659    if (isStopped())
     
    665665            startBackgroundParser();
    666666
    667         HTMLParserThread::shared()->postTask(bind(
    668             &BackgroundHTMLParser::append, m_backgroundParser, source.toString().isolatedCopy()));
     667        ASSERT(inputSource->hasOneRef());
     668        Closure closure = bind(&BackgroundHTMLParser::append, m_backgroundParser, String(inputSource));
     669        // NOTE: Important that the String temporary is destroyed before we post the task
     670        // otherwise the String could call deref() on a StringImpl now owned by the background parser.
     671        // We would like to ASSERT(closure.arg3()->hasOneRef()) but sadly the args are private.
     672        HTMLParserThread::shared()->postTask(closure);
    669673        return;
    670674    }
     
    674678    // but we need to ensure it isn't deleted yet.
    675679    RefPtr<HTMLDocumentParser> protect(this);
     680    String source(inputSource);
    676681
    677682    if (m_preloadScanner) {
  • trunk/Source/WebCore/html/parser/HTMLDocumentParser.h

    r144407 r144498  
    9999protected:
    100100    virtual void insert(const SegmentedString&) OVERRIDE;
    101     virtual void append(const SegmentedString&) OVERRIDE;
     101    virtual void append(PassRefPtr<StringImpl>) OVERRIDE;
    102102    virtual void finish() OVERRIDE;
    103103
  • trunk/Source/WebCore/html/parser/HTMLViewSourceParser.cpp

    r142712 r144498  
    6363}
    6464
    65 void HTMLViewSourceParser::append(const SegmentedString& input)
     65void HTMLViewSourceParser::append(PassRefPtr<StringImpl> input)
    6666{
    67     m_input.appendToEnd(input);
     67    m_input.appendToEnd(String(input));
    6868    pumpTokenizer();
    6969}
  • trunk/Source/WebCore/html/parser/HTMLViewSourceParser.h

    r140036 r144498  
    6060    // DocumentParser
    6161    virtual void insert(const SegmentedString&);
    62     virtual void append(const SegmentedString&);
     62    virtual void append(PassRefPtr<StringImpl>);
    6363    virtual void finish();
    6464
  • trunk/Source/WebCore/html/parser/TextDocumentParser.cpp

    r142641 r144498  
    4545}
    4646
    47 void TextDocumentParser::append(const SegmentedString& text)
     47void TextDocumentParser::append(PassRefPtr<StringImpl> text)
    4848{
    4949    if (!m_haveInsertedFakePreElement)
  • trunk/Source/WebCore/html/parser/TextDocumentParser.h

    r95901 r144498  
    4242    explicit TextDocumentParser(HTMLDocument*);
    4343
    44     virtual void append(const SegmentedString&);
     44    virtual void append(PassRefPtr<StringImpl>);
    4545    void insertFakePreElement();
    4646
  • trunk/Source/WebCore/loader/DocumentWriter.cpp

    r144000 r144498  
    8181        if (DocumentParser* parser = m_frame->document()->parser()) {
    8282            parser->pinToMainThread();
    83             parser->append(source);
     83            // Because we're pinned to the main thread we don't need to worry about
     84            // passing ownership of the source string.
     85            parser->append(source.impl());
    8486        }
    8587    }
  • trunk/Source/WebCore/xml/parser/XMLDocumentParser.cpp

    r144446 r144498  
    113113}
    114114
    115 void XMLDocumentParser::append(const SegmentedString& source)
    116 {
     115void XMLDocumentParser::append(PassRefPtr<StringImpl> inputSource)
     116{
     117    SegmentedString source(inputSource);
    117118    if (m_sawXSLTransform || !m_sawFirstElement)
    118119        m_originalSourceForTransform.append(source);
  • trunk/Source/WebCore/xml/parser/XMLDocumentParser.h

    r144446 r144498  
    108108        // From DocumentParser
    109109        virtual void insert(const SegmentedString&);
    110         virtual void append(const SegmentedString&);
     110        virtual void append(PassRefPtr<StringImpl>);
    111111        virtual void finish();
    112112        virtual bool isWaitingForScripts() const;
  • trunk/Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp

    r144446 r144498  
    14451445    SegmentedString rest = m_pendingSrc;
    14461446    m_pendingSrc.clear();
    1447     append(rest);
     1447    // There is normally only one string left, so toString() shouldn't copy.
     1448    // In any case, the XML parser runs on the main thread and it's OK if
     1449    // the passed string has more than one reference.
     1450    append(rest.toString().impl());
    14481451
    14491452    // Finally, if finish() has been called and write() didn't result
Note: See TracChangeset for help on using the changeset viewer.