[SCM] WebKit Debian packaging branch, debian/unstable, updated. debian/1.1.15-1-40151-g37bb677

hyatt hyatt at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 07:10:21 UTC 2009


The following commit has been merged in the debian/unstable branch:
commit fd2f79aee29982fb4be8165c27d109e64da4fe51
Author: hyatt <hyatt at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Mon Dec 2 01:32:01 2002 +0000

    	Convert the WebCore cache from LRU to size-adjusted and
    	popularity-aware LRU (LRU-SP).  With the improved cache,
    	the size restriction on images can be relaxed back to 40K
    	(from 16K) while retaining the same score on cvs-base.
    	This should result in better real-world performance.
    
            * khtml/misc/loader.cpp:
            (CachedObject::ref):
            (CachedObject::setSize):
            (m_tail):
            (LRUList::~LRUList):
            (Cache::flush):
            (FastLog2):
            (Cache::getLRUListFor):
            (Cache::removeFromLRUList):
            (Cache::insertInLRUList):
            (Cache::adjustSize):
            * khtml/misc/loader.h:
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@2901 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog-2002-12-03 b/WebCore/ChangeLog-2002-12-03
index febc32b..571abeb 100644
--- a/WebCore/ChangeLog-2002-12-03
+++ b/WebCore/ChangeLog-2002-12-03
@@ -1,3 +1,24 @@
+2002-12-01  David Hyatt  <hyatt at apple.com>
+
+	Convert the WebCore cache from LRU to size-adjusted and
+	popularity-aware LRU (LRU-SP).  With the improved cache,
+	the size restriction on images can be relaxed back to 40K
+	(from 16K) while retaining the same score on cvs-base.
+	This should result in better real-world performance.
+	
+        * khtml/misc/loader.cpp:
+        (CachedObject::ref):
+        (CachedObject::setSize):
+        (m_tail):
+        (LRUList::~LRUList):
+        (Cache::flush):
+        (FastLog2):
+        (Cache::getLRUListFor):
+        (Cache::removeFromLRUList):
+        (Cache::insertInLRUList):
+        (Cache::adjustSize):
+        * khtml/misc/loader.h:
+
 2002-11-29  Don Melton  <gramps at apple.com>
 
         * khtml/css/html4.css:
diff --git a/WebCore/ChangeLog-2003-10-25 b/WebCore/ChangeLog-2003-10-25
index febc32b..571abeb 100644
--- a/WebCore/ChangeLog-2003-10-25
+++ b/WebCore/ChangeLog-2003-10-25
@@ -1,3 +1,24 @@
+2002-12-01  David Hyatt  <hyatt at apple.com>
+
+	Convert the WebCore cache from LRU to size-adjusted and
+	popularity-aware LRU (LRU-SP).  With the improved cache,
+	the size restriction on images can be relaxed back to 40K
+	(from 16K) while retaining the same score on cvs-base.
+	This should result in better real-world performance.
+	
+        * khtml/misc/loader.cpp:
+        (CachedObject::ref):
+        (CachedObject::setSize):
+        (m_tail):
+        (LRUList::~LRUList):
+        (Cache::flush):
+        (FastLog2):
+        (Cache::getLRUListFor):
+        (Cache::removeFromLRUList):
+        (Cache::insertInLRUList):
+        (Cache::adjustSize):
+        * khtml/misc/loader.h:
+
 2002-11-29  Don Melton  <gramps at apple.com>
 
         * khtml/css/html4.css:
diff --git a/WebCore/ChangeLog-2005-08-23 b/WebCore/ChangeLog-2005-08-23
index febc32b..571abeb 100644
--- a/WebCore/ChangeLog-2005-08-23
+++ b/WebCore/ChangeLog-2005-08-23
@@ -1,3 +1,24 @@
+2002-12-01  David Hyatt  <hyatt at apple.com>
+
+	Convert the WebCore cache from LRU to size-adjusted and
+	popularity-aware LRU (LRU-SP).  With the improved cache,
+	the size restriction on images can be relaxed back to 40K
+	(from 16K) while retaining the same score on cvs-base.
+	This should result in better real-world performance.
+	
+        * khtml/misc/loader.cpp:
+        (CachedObject::ref):
+        (CachedObject::setSize):
+        (m_tail):
+        (LRUList::~LRUList):
+        (Cache::flush):
+        (FastLog2):
+        (Cache::getLRUListFor):
+        (Cache::removeFromLRUList):
+        (Cache::insertInLRUList):
+        (Cache::adjustSize):
+        * khtml/misc/loader.h:
+
 2002-11-29  Don Melton  <gramps at apple.com>
 
         * khtml/css/html4.css:
diff --git a/WebCore/khtml/misc/loader.cpp b/WebCore/khtml/misc/loader.cpp
index e9581f6..82e1c62 100644
--- a/WebCore/khtml/misc/loader.cpp
+++ b/WebCore/khtml/misc/loader.cpp
@@ -31,7 +31,7 @@
 #include "loader.h"
 
 // up to which size is a picture for sure cacheable
-#define MAXCACHEABLE 16*1024
+#define MAXCACHEABLE 40*1024
 // default cache size
 #define DEFCACHESIZE 4096*1024
 
@@ -146,6 +146,7 @@ void CachedObject::ref(CachedObjectClient *c)
     m_clients.remove(c);
     m_clients.append(c);
     Cache::removeFromLRUList(this);
+    increaseAccessCount();
 }
 
 void CachedObject::deref(CachedObjectClient *c)
@@ -157,8 +158,16 @@ void CachedObject::deref(CachedObjectClient *c)
 
 void CachedObject::setSize(int size)
 {
-    Cache::adjustSize(this, size - m_size);
+    bool sizeChanged = Cache::adjustSize(this, size - m_size);
+
+    // The object must now be moved to a different queue, since its size has been changed.
+    if (sizeChanged && allowInLRUList())
+        Cache::removeFromLRUList(this);
+
     m_size = size;
+    
+    if (sizeChanged && allowInLRUList())
+        Cache::insertInLRUList(this);
 }
 
 // -------------------------------------------------------------------------------------------
@@ -1369,6 +1378,13 @@ KIO::Job *Loader::jobForRequest( const DOM::DOMString &url ) const
 // ----------------------------------------------------------------------------
 
 
+LRUList::LRUList()
+:m_head(0), m_tail(0) 
+{}
+
+LRUList::~LRUList()
+{}
+
 QDict<CachedObject> *Cache::cache = 0;
 QPtrList<DocLoader>* Cache::docloader = 0;
 Loader *Cache::m_loader = 0;
@@ -1379,11 +1395,10 @@ int Cache::flushCount = 0;
 QPixmap *Cache::nullPixmap = 0;
 QPixmap *Cache::brokenPixmap = 0;
 
-CachedObject *Cache::m_headOfLRUList = 0;
-CachedObject *Cache::m_tailOfLRUList = 0;
 CachedObject *Cache::m_headOfUncacheableList = 0;
-int Cache::m_totalSizeOfLRUList = 0;
+int Cache::m_totalSizeOfLRULists = 0;
 int Cache::m_countOfLRUAndUncacheableLists;
+LRUList Cache::m_LRULists[MAX_LRU_LISTS];
 
 void Cache::init()
 {
@@ -1687,8 +1702,15 @@ void Cache::flush(bool force)
 
     while (m_headOfUncacheableList)
         removeCacheEntry(m_headOfUncacheableList);
-    while (m_totalSizeOfLRUList > maxSize)
-        removeCacheEntry(m_tailOfLRUList);
+    
+    for (int i = MAX_LRU_LISTS-1; i>=0; i--) {
+        if (m_totalSizeOfLRULists <= maxSize)
+            break;
+            
+        while (m_totalSizeOfLRULists > maxSize && m_LRULists[i].m_tail) {
+            removeCacheEntry(m_LRULists[i].m_tail);
+        }
+    }
 
     flushCount = m_countOfLRUAndUncacheableLists+10; // Flush again when the cache has grown.
 #ifdef CACHE_DEBUG
@@ -1804,12 +1826,52 @@ void Cache::removeCacheEntry( CachedObject *object )
      delete object;
 }
 
+#define FAST_LOG2(_log2,_n)   \
+      unsigned int j_ = (unsigned int)(_n);   \
+      (_log2) = 0;                    \
+      if ((j_) & ((j_)-1))            \
+      (_log2) += 1;               \
+      if ((j_) >> 16)                 \
+      (_log2) += 16, (j_) >>= 16; \
+      if ((j_) >> 8)                  \
+      (_log2) += 8, (j_) >>= 8;   \
+      if ((j_) >> 4)                  \
+      (_log2) += 4, (j_) >>= 4;   \
+      if ((j_) >> 2)                  \
+      (_log2) += 2, (j_) >>= 2;   \
+      if ((j_) >> 1)                  \
+      (_log2) += 1;
+
+int FastLog2(unsigned int i) {
+    int log2;
+    FAST_LOG2(log2,i);
+    return log2;
+}
+
+LRUList* Cache::getLRUListFor(CachedObject* o)
+{
+    ASSERT(o->accessCount());
+    int sizeLog = FastLog2(o->size());
+    int queueIndex = sizeLog/o->accessCount();
+    queueIndex--;
+    if (queueIndex < 0)
+        queueIndex = 0;
+    if (queueIndex >= MAX_LRU_LISTS)
+        queueIndex = MAX_LRU_LISTS-1;
+    return &(m_LRULists[queueIndex]);
+}
+
 void Cache::removeFromLRUList(CachedObject *object)
 {
+    if (!object->accessCount())
+        return; // No way we can be in a queue yet.
+        
     CachedObject *next = object->m_nextInLRUList;
     CachedObject *prev = object->m_prevInLRUList;
     bool uncacheable = object->status() == CachedObject::Uncacheable;
-    CachedObject *&head = uncacheable ? m_headOfUncacheableList : m_headOfLRUList;
+    
+    LRUList* list = uncacheable ? 0 : getLRUListFor(object);
+    CachedObject *&head = uncacheable ? m_headOfUncacheableList : list->m_head;
     
     if (next == 0 && prev == 0 && head != object) {
         return;
@@ -1820,8 +1882,8 @@ void Cache::removeFromLRUList(CachedObject *object)
     
     if (next)
         next->m_prevInLRUList = prev;
-    else if (m_tailOfLRUList == object)
-        m_tailOfLRUList = prev;
+    else if (!uncacheable && list->m_tail == object)
+        list->m_tail = prev;
 
     if (prev)
         prev->m_nextInLRUList = next;
@@ -1831,7 +1893,7 @@ void Cache::removeFromLRUList(CachedObject *object)
     --m_countOfLRUAndUncacheableLists;
     
     if (!uncacheable)
-        m_totalSizeOfLRUList -= object->size();
+        m_totalSizeOfLRULists -= object->size();
 }
 
 void Cache::moveToHeadOfLRUList(CachedObject *object)
@@ -1846,8 +1908,10 @@ void Cache::insertInLRUList(CachedObject *object)
     if (!object->allowInLRUList())
         return;
     
+    LRUList* list = getLRUListFor(object);
+    
     bool uncacheable = object->status() == CachedObject::Uncacheable;
-    CachedObject *&head = uncacheable ? m_headOfUncacheableList : m_headOfLRUList;
+    CachedObject *&head = uncacheable ? m_headOfUncacheableList : list->m_head;
 
     object->m_nextInLRUList = head;
     if (head)
@@ -1855,25 +1919,25 @@ void Cache::insertInLRUList(CachedObject *object)
     head = object;
     
     if (object->m_nextInLRUList == 0 && !uncacheable)
-        m_tailOfLRUList = object;
+        list->m_tail = object;
     
     ++m_countOfLRUAndUncacheableLists;
     
     if (!uncacheable)
-        m_totalSizeOfLRUList += object->size();
+        m_totalSizeOfLRULists += object->size();
 }
 
-void Cache::adjustSize(CachedObject *object, int delta)
+bool Cache::adjustSize(CachedObject *object, int delta)
 {
-    if (object->m_nextInLRUList == 0 && object->m_prevInLRUList == 0 && m_headOfLRUList != object) {
-        return;
-    }
+    if (object->status() == CachedObject::Uncacheable)
+        return false;
 
-    if (object->status() == CachedObject::Uncacheable) {
-        return;
-    }
+    if (object->m_nextInLRUList == 0 && object->m_prevInLRUList == 0 &&
+        getLRUListFor(object)->m_head != object)
+        return false;
     
-    m_totalSizeOfLRUList += delta;
+    m_totalSizeOfLRULists += delta;
+    return delta != 0;
 }
 
 // --------------------------------------
diff --git a/WebCore/khtml/misc/loader.h b/WebCore/khtml/misc/loader.h
index d0bb51b..4b8e201 100644
--- a/WebCore/khtml/misc/loader.h
+++ b/WebCore/khtml/misc/loader.h
@@ -76,6 +76,16 @@ namespace khtml
     class Request;
     class DocLoader;
 
+ #define MAX_LRU_LISTS 20
+    
+    struct LRUList {
+        CachedObject* m_head;
+        CachedObject* m_tail;
+    
+        LRUList();
+        ~LRUList();
+    };
+    
     /**
      * @internal
      *
@@ -97,10 +107,10 @@ namespace khtml
 	    NotCached,    // this URL is not cached
 	    Unknown,      // let imagecache decide what to do with it
 	    New,          // inserting new image
-            Pending,      // only partially loaded
+        Pending,      // only partially loaded
 	    Persistent,   // never delete this pixmap
 	    Cached,       // regular case
-	    Uncacheable   // to big to be cached,
+	    Uncacheable   // too big to be cached,
 	};  	          // will be destroyed as soon as possible
 
 	CachedObject(const DOM::DOMString &url, Type type, KIO::CacheControl _cachePolicy, time_t _expireDate, int size = 0)
@@ -113,13 +123,16 @@ namespace khtml
 	    m_cachePolicy = _cachePolicy;
 	    m_request = 0;
 #if APPLE_CHANGES
-            m_response = 0;
+        m_response = 0;
 #endif            
 	    m_expireDate = _expireDate;
-            m_deleted = false;
-            m_expireDateChanged = false;
-            m_nextInLRUList = 0;
-            m_prevInLRUList = 0;
+        m_deleted = false;
+        m_expireDateChanged = false;
+        
+        m_accessCount = 0;
+        
+        m_nextInLRUList = 0;
+        m_prevInLRUList = 0;
 	}
 	virtual ~CachedObject();
 
@@ -138,6 +151,9 @@ namespace khtml
 
 	int size() const { return m_size; }
 
+    int accessCount() const { return m_accessCount; }
+    void increaseAccessCount() { m_accessCount++; }
+    
 	/**
 	 * computes the status of an object after loading.
 	 * the result depends on the objects size and the size of the cache
@@ -190,6 +206,8 @@ namespace khtml
 	Status m_status;
     private:
 	int m_size;
+    int m_accessCount;
+    
     protected:
 	time_t m_expireDate;
 	KIO::CacheControl m_cachePolicy;
@@ -547,29 +565,30 @@ namespace khtml
 
         static void insertInLRUList(CachedObject *);
         static void removeFromLRUList(CachedObject *);
-        static void adjustSize(CachedObject *, int sizeDelta);
+        static bool adjustSize(CachedObject *, int sizeDelta);
+        
+        static LRUList* getLRUListFor(CachedObject* o);
         
         static void checkLRUAndUncacheableListIntegrity();
 
-        protected:
-	static QDict<CachedObject> *cache;
+    protected:
+        static QDict<CachedObject> *cache;
         static QPtrList<DocLoader>* docloader;
-
-	static int maxSize;
-	static int flushCount;
-
-	static Loader *m_loader;
-
+    
+        static int maxSize;
+        static int flushCount;
+    
+        static Loader *m_loader;
+    
         static unsigned long s_ulRefCnt;
-
+    
         static void moveToHeadOfLRUList(CachedObject *);
-
-	static CachedObject *m_headOfLRUList;
-	static CachedObject *m_tailOfLRUList;
-        static int m_totalSizeOfLRUList;
-        
-	static CachedObject *m_headOfUncacheableList;
-        
+    
+        static LRUList m_LRULists[];
+        static int m_totalSizeOfLRULists;
+            
+        static CachedObject *m_headOfUncacheableList;
+            
         static int m_countOfLRUAndUncacheableLists;
     };
 

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list