Changeset 21245 in webkit


Ignore:
Timestamp:
May 3, 2007, 9:35:28 PM (18 years ago)
Author:
beidson
Message:

Reviewed by Oliver

Resolve an outstanding FIXME in Loader::numRequests()

Before, numRequests() would iterate through the list of requests pending load and the list of currently
loading requests and tally up a count matching the current DocLoader.

I noticed while studying and cleaning up the loader code that numRequests() is potentially very hot!
Indeed load a complex site with many resources and multiple frames, and this method gets called very often,
tallying up this number every time.

The FIXME was to keep a collection of Requests mapped to each DocLoader. In reality, since this map would
simply be used for retrieving a count, that was overkill. Keeping a request count in the DocLoader itself
along with maintaining that count in Loader as requests come and go is a much better way to do this.

  • loader/DocLoader.cpp: (WebCore::DocLoader::DocLoader): (WebCore::DocLoader::incrementRequestCount): (WebCore::DocLoader::decrementRequestCount): (WebCore::DocLoader::requestCount): Emulate the defunct Loader::numRequests()
  • loader/DocLoader.h:
  • loader/FrameLoader.cpp: (WebCore::numRequests): Call DocLoader::requestCount() directly (WebCore::FrameLoader::checkCompleted): Use numRequests()
  • loader/loader.cpp: (WebCore::Loader::load): Increment the DocLoader's request count (WebCore::Loader::servePendingRequests): If the SubresourceLoader failed to create, decrement the count (WebCore::Loader::didFinishLoading): If the Request is not Multipart, decrement the count (WebCore::Loader::didFail): If the Request is not Multipart, decrement the count (WebCore::Loader::didReceiveResponse): If the Request becomes Multipart, decrement the count (WebCore::Loader::cancelRequests): Decrement the count for the pending requests being tossed, and ASSERT the count is zero after all requests have been cancelled
  • loader/loader.h:
Location:
trunk/WebCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r21244 r21245  
    1 <<<<<<< .mine
     12007-05-03  Brady Eidson  <beidson@apple.com>
     2
     3        Reviewed by Oliver
     4
     5        Resolve an outstanding FIXME in Loader::numRequests()
     6
     7        Before, numRequests() would iterate through the list of requests pending load and the list of currently
     8        loading requests and tally up a count matching the current DocLoader.
     9
     10        I noticed while studying and cleaning up the loader code that numRequests() is potentially very hot!
     11        Indeed load a complex site with many resources and multiple frames, and this method gets called very often,
     12        tallying up this number every time.
     13
     14        The FIXME was to keep a collection of Requests mapped to each DocLoader.  In reality, since this map would
     15        simply be used for retrieving a count, that was overkill.  Keeping a request count in the DocLoader itself
     16        along with maintaining that count in Loader as requests come and go is a much better way to do this.
     17
     18        * loader/DocLoader.cpp:
     19        (WebCore::DocLoader::DocLoader):
     20        (WebCore::DocLoader::incrementRequestCount):
     21        (WebCore::DocLoader::decrementRequestCount):
     22        (WebCore::DocLoader::requestCount): Emulate the defunct Loader::numRequests()
     23        * loader/DocLoader.h:
     24
     25        * loader/FrameLoader.cpp:
     26        (WebCore::numRequests): Call DocLoader::requestCount() directly
     27        (WebCore::FrameLoader::checkCompleted): Use numRequests()
     28
     29        * loader/loader.cpp:
     30        (WebCore::Loader::load): Increment the DocLoader's request count
     31        (WebCore::Loader::servePendingRequests): If the SubresourceLoader failed to create, decrement the count
     32        (WebCore::Loader::didFinishLoading): If the Request is not Multipart, decrement the count
     33        (WebCore::Loader::didFail): If the Request is not Multipart, decrement the count
     34        (WebCore::Loader::didReceiveResponse): If the Request becomes Multipart, decrement the count
     35        (WebCore::Loader::cancelRequests): Decrement the count for the pending requests being tossed, and ASSERT the
     36          count is zero after all requests have been cancelled
     37        * loader/loader.h:
     38
    2392007-05-03  Geoffrey Garen  <ggaren@apple.com>
    340
     
    1956        * loader/FrameLoader.h:
    2057
    21 =======
    22582007-05-03  Justin Garcia  <justin.garcia@apple.com>
    2359
     
    3268        Nil-check checkAncestor and lastClosed.
    3369
    34 >>>>>>> .r21243
    35702007-05-03  Timothy Hatcher  <timothy@apple.com>
    3671
  • trunk/WebCore/loader/DocLoader.cpp

    r20674 r21245  
    4646    , m_frame(frame)
    4747    , m_doc(doc)
     48    , m_requestCount(0)
    4849    , m_autoLoadImages(true)
    4950    , m_loadInProgress(false)
     
    206207}
    207208
    208 }
     209void DocLoader::incrementRequestCount()
     210{
     211    ++m_requestCount;
     212}
     213
     214void DocLoader::decrementRequestCount()
     215{
     216    --m_requestCount;
     217    ASSERT(m_requestCount > -1);
     218}
     219
     220int DocLoader::requestCount()
     221{
     222    if (loadInProgress())
     223         return m_requestCount + 1;
     224    return m_requestCount;
     225}
     226
     227}
  • trunk/WebCore/loader/DocLoader.h

    r21009 r21245  
    8989#endif
    9090
     91    void incrementRequestCount();
     92    void decrementRequestCount();
     93    int requestCount();
    9194private:
    9295    CachedResource* requestResource(CachedResource::Type, const String& url, const String* charset = 0, bool skipCanLoadCheck = false);
     
    102105    Document *m_doc;
    103106   
     107    int m_requestCount;
     108   
    104109    //29 bits left
    105110    bool m_autoLoadImages : 1;
  • trunk/WebCore/loader/FrameLoader.cpp

    r21244 r21245  
    196196static int numRequests(Document* document)
    197197{
    198     if (document)
    199         return cache()->loader()->numRequests(document->docLoader());
    200     return 0;
     198    if (!document)
     199        return 0;
     200   
     201    return document->docLoader()->requestCount();
    201202}
    202203
     
    11271128
    11281129    // Still waiting for images/scripts?
    1129     if (m_frame->document() && m_frame->document()->docLoader())
    1130         if (cache()->loader()->numRequests(m_frame->document()->docLoader()))
     1130    if (m_frame->document())
     1131        if (numRequests(m_frame->document()))
    11311132            return;
    11321133
  • trunk/WebCore/loader/loader.cpp

    r20299 r21245  
    5959void Loader::load(DocLoader* dl, CachedResource* object, bool incremental, bool skipCanLoadCheck)
    6060{
     61    ASSERT(dl);
    6162    Request* req = new Request(dl, object, incremental);
    6263    m_requestsPending.append(req);
     64    dl->incrementRequestCount();
    6365    servePendingRequests(skipCanLoadCheck);
    6466}
     
    7173    // get the first pending request
    7274    Request* req = m_requestsPending.take(0);
     75    DocLoader* dl = req->docLoader();
     76    dl->decrementRequestCount();
    7377
    7478    ResourceRequest request(req->cachedResource()->url());
     
    7680    if (!req->cachedResource()->accept().isEmpty())
    7781        request.setHTTPAccept(req->cachedResource()->accept());
    78     if (req->docLoader())  {
    79         KURL r = req->docLoader()->doc()->URL();
    80         if (r.protocol().startsWith("http") && r.path().isEmpty())
    81             r.setPath("/");
    82         request.setHTTPReferrer(r.url());
    83         DeprecatedString domain = r.host();
    84         if (req->docLoader()->doc()->isHTMLDocument())
    85             domain = static_cast<HTMLDocument*>(req->docLoader()->doc())->domain().deprecatedString();
    86     }
    87    
    88     RefPtr<SubresourceLoader> loader = SubresourceLoader::create(req->docLoader()->doc()->frame(), this, request, skipCanLoadCheck);
    89 
    90     if (loader)
     82
     83    KURL r = dl->doc()->URL();
     84    if (r.protocol().startsWith("http") && r.path().isEmpty())
     85        r.setPath("/");
     86    request.setHTTPReferrer(r.url());
     87    DeprecatedString domain = r.host();
     88    if (dl->doc()->isHTMLDocument())
     89        domain = static_cast<HTMLDocument*>(dl->doc())->domain().deprecatedString();
     90   
     91    RefPtr<SubresourceLoader> loader = SubresourceLoader::create(dl->doc()->frame(), this, request, skipCanLoadCheck);
     92
     93    if (loader) {
    9194        m_requestsLoading.add(loader.release(), req);
     95        dl->incrementRequestCount();
     96    }
    9297}
    9398
     
    100105    Request* req = i->second;
    101106    m_requestsLoading.remove(i);
     107    DocLoader* docLoader = req->docLoader();
     108    if (!req->isMultipart())
     109        docLoader->decrementRequestCount();
    102110
    103111    CachedResource* object = req->cachedResource();
    104     DocLoader* docLoader = req->docLoader();
    105112
    106113    docLoader->setLoadInProgress(true);
     
    127134    Request* req = i->second;
    128135    m_requestsLoading.remove(i);
     136    DocLoader* docLoader = req->docLoader();
     137    if (!req->isMultipart())
     138        docLoader->decrementRequestCount();
    129139
    130140    CachedResource* object = req->cachedResource();
    131     DocLoader* docLoader = req->docLoader();
    132141
    133142    if (!cancelled) {
     
    161170    } else if (response.isMultipart()) {
    162171        req->setIsMultipart(true);
     172       
     173        // We don't count multiParts in a DocLoader's request count
     174        req->docLoader()->decrementRequestCount();
     175           
    163176        // If we get a multipart response, we must have a handle
    164177        ASSERT(loader->handle());
     
    184197}
    185198
    186 int Loader::numRequests(DocLoader* dl) const
    187 {
    188     // FIXME: Maybe we should keep a collection of requests by DocLoader, so we can do this instantly.
    189 
    190     int res = 0;
    191 
    192     DeprecatedPtrListIterator<Request> pIt(m_requestsPending);
    193     for (; pIt.current(); ++pIt) {
    194         if (pIt.current()->docLoader() == dl)
    195             res++;
    196     }
    197 
    198     RequestMap::const_iterator end = m_requestsLoading.end();
    199     for (RequestMap::const_iterator i = m_requestsLoading.begin(); !(i == end); ++i) {
    200         Request* r = i->second;
    201         res += (r->docLoader() == dl && !r->isMultipart());
    202     }
    203 
    204     if (dl->loadInProgress())
    205         res++;
    206 
    207     return res;
    208 }
    209 
    210199void Loader::cancelRequests(DocLoader* dl)
    211200{
     
    215204            cache()->remove(pIt.current()->cachedResource());
    216205            m_requestsPending.remove(pIt);
     206            dl->decrementRequestCount();
    217207        } else
    218208            ++pIt;
     
    232222        didFail(loader, true);
    233223    }
     224   
     225    if (dl->loadInProgress())
     226        ASSERT(dl->requestCount() == 1);
     227    else
     228        ASSERT(dl->requestCount() == 0);
    234229}
    235230
  • trunk/WebCore/loader/loader.h

    r20299 r21245  
    5252        void load(DocLoader*, CachedResource*, bool incremental = true, bool skipCanLoadCheck = false);
    5353
    54         int numRequests(DocLoader*) const;
    5554        void cancelRequests(DocLoader*);
    56 
    5755    private:
    5856        virtual void didReceiveResponse(SubresourceLoader*, const ResourceResponse&);
Note: See TracChangeset for help on using the changeset viewer.