Changeset 35801 in webkit


Ignore:
Timestamp:
Aug 15, 2008 3:58:06 PM (16 years ago)
Author:
Antti Koivisto
Message:

2008-08-15 Antti Koivisto <Antti Koivisto>

Reviewed by Anders.

Don't start preloading body resources before the head is complete. This prevents
body preloads from slowing down initial display when there is limited amount
of bandwidth available.


Works by queuing up found body preloads to DocLoader and only issuing them
after document has rendering.


With bandwidth capped to 300kbit/s this speeds up cnn.com initial display by ~25% or 5s
without affecting complete load time.

  • html/PreloadScanner.cpp: (WebCore::PreloadScanner::PreloadScanner): (WebCore::PreloadScanner::scanningBody): (WebCore::PreloadScanner::emitTag): (WebCore::PreloadScanner::emitCSSRule):
  • html/PreloadScanner.h:
  • loader/DocLoader.cpp: (WebCore::DocLoader::preload): (WebCore::DocLoader::checkForPendingPreloads): (WebCore::DocLoader::requestPreload):
  • loader/DocLoader.h:
  • loader/loader.cpp: (WebCore::Loader::Host::didFinishLoading): (WebCore::Loader::Host::didFail):
Location:
trunk/WebCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r35800 r35801  
     12008-08-15  Antti Koivisto  <antti@apple.com>
     2
     3        Reviewed by Anders.
     4
     5        Don't start preloading body resources before the head is complete. This prevents
     6        body preloads from slowing down initial display when there is limited amount
     7        of bandwidth available.
     8       
     9        Works by queuing up found body preloads to DocLoader and only issuing them
     10        after document has rendering.
     11       
     12        With bandwidth capped to 300kbit/s this speeds up cnn.com initial display by ~25% or 5s
     13        without affecting complete load time.
     14
     15        * html/PreloadScanner.cpp:
     16        (WebCore::PreloadScanner::PreloadScanner):
     17        (WebCore::PreloadScanner::scanningBody):
     18        (WebCore::PreloadScanner::emitTag):
     19        (WebCore::PreloadScanner::emitCSSRule):
     20        * html/PreloadScanner.h:
     21        * loader/DocLoader.cpp:
     22        (WebCore::DocLoader::preload):
     23        (WebCore::DocLoader::checkForPendingPreloads):
     24        (WebCore::DocLoader::requestPreload):
     25        * loader/DocLoader.h:
     26        * loader/loader.cpp:
     27        (WebCore::Loader::Host::didFinishLoading):
     28        (WebCore::Loader::Host::didFail):
     29
    1302008-08-15  Ada Chan  <adachan@apple.com>
    231
  • trunk/WebCore/html/PreloadScanner.cpp

    r35298 r35801  
    6767    : m_inProgress(false)
    6868    , m_timeUsed(0)
     69    , m_bodySeen(false)
    6970    , m_document(doc)
    7071{
     
    119120    m_cssRule.clear();
    120121    m_cssRuleValue.clear();
     122}
     123   
     124bool PreloadScanner::scanningBody() const
     125{
     126    return m_document->body() || m_bodySeen;
    121127}
    122128   
     
    811817        m_contentModel = PCDATA;
    812818   
     819    if (tag == bodyTag)
     820        m_bodySeen = true;
     821   
    813822    if (m_urlToLoad.isEmpty()) {
    814823        m_linkIsStyleSheet = false;
     
    817826   
    818827    if (tag == scriptTag)
    819         m_document->docLoader()->preload(CachedResource::Script, m_urlToLoad, m_charset);
     828        m_document->docLoader()->preload(CachedResource::Script, m_urlToLoad, m_charset, scanningBody());
    820829    else if (tag == imgTag)
    821         m_document->docLoader()->preload(CachedResource::ImageResource, m_urlToLoad, String());
     830        m_document->docLoader()->preload(CachedResource::ImageResource, m_urlToLoad, String(), scanningBody());
    822831    else if (tag == linkTag && m_linkIsStyleSheet)
    823         m_document->docLoader()->preload(CachedResource::CSSStyleSheet, m_urlToLoad, m_charset);
     832        m_document->docLoader()->preload(CachedResource::CSSStyleSheet, m_urlToLoad, m_charset, scanningBody());
    824833
    825834    m_urlToLoad = String();
     
    835844        String url = parseURL(value);
    836845        if (!url.isEmpty())
    837             m_document->docLoader()->preload(CachedResource::CSSStyleSheet, url, String());
     846            m_document->docLoader()->preload(CachedResource::CSSStyleSheet, url, String(), scanningBody());
    838847    }
    839848    m_cssRule.clear();
  • trunk/WebCore/html/PreloadScanner.h

    r31964 r35801  
    4646        void end();
    4747        bool inProgress() const { return m_inProgress; }
     48       
     49        bool scanningBody() const;
    4850       
    4951        static unsigned consumeEntity(SegmentedString&, bool& notEnoughCharacters);
     
    134136        double m_timeUsed;
    135137       
     138        bool m_bodySeen;
    136139        Document* m_document;
    137140    };
  • trunk/WebCore/loader/DocLoader.cpp

    r34815 r35801  
    300300}
    301301   
    302 void DocLoader::preload(CachedResource::Type type, const String& url, const String& charset)
     302void DocLoader::preload(CachedResource::Type type, const String& url, const String& charset, bool referencedFromBody)
     303{
     304    bool hasRendering = m_doc->body() && m_doc->body()->renderer();
     305    if (!hasRendering && (referencedFromBody || type == CachedResource::ImageResource)) {
     306        // Don't preload images or body resources before we have something to draw. This prevents
     307        // preloads from body delaying first display when bandwidth is limited.
     308        PendingPreload pendingPreload = { type, url, charset };
     309        m_pendingPreloads.append(pendingPreload);
     310        return;
     311    }
     312    requestPreload(type, url, charset);
     313}
     314
     315void DocLoader::checkForPendingPreloads()
     316{
     317    unsigned count = m_pendingPreloads.size();
     318    if (!count || !m_doc->body() || !m_doc->body()->renderer())
     319        return;
     320    for (unsigned i = 0; i < count; ++i) {
     321        PendingPreload& preload = m_pendingPreloads[i];
     322        requestPreload(preload.m_type, preload.m_url, preload.m_charset);
     323    }
     324    m_pendingPreloads.clear();
     325}
     326
     327void DocLoader::requestPreload(CachedResource::Type type, const String& url, const String& charset)
    303328{
    304329    String encoding;
  • trunk/WebCore/loader/DocLoader.h

    r34815 r35801  
    9999   
    100100    void clearPreloads();
    101     void preload(CachedResource::Type type, const String& url, const String& charset);
     101    void preload(CachedResource::Type, const String& url, const String& charset, bool referencedFromBody);
     102    void checkForPendingPreloads();
    102103    void printPreloadStats();
    103104   
    104105private:
    105106    CachedResource* requestResource(CachedResource::Type, const String& url, const String& charset, bool isPreload = false);
     107    void requestPreload(CachedResource::Type, const String& url, const String& charset);
    106108
    107109    void checkForReload(const KURL&);
     
    117119   
    118120    ListHashSet<CachedResource*> m_preloads;
     121    struct PendingPreload {
     122        CachedResource::Type m_type;
     123        String m_url;
     124        String m_charset;
     125    };
     126    Vector<PendingPreload> m_pendingPreloads;
    119127   
    120128    //29 bits left
  • trunk/WebCore/loader/loader.cpp

    r35799 r35801  
    282282
    283283    docLoader->setLoadInProgress(false);
     284   
     285    docLoader->checkForPendingPreloads();
    284286
    285287#if REQUEST_DEBUG
     
    321323   
    322324    delete request;
     325   
     326    docLoader->checkForPendingPreloads();
    323327
    324328    servePendingRequests();
Note: See TracChangeset for help on using the changeset viewer.