Changeset 93990 in webkit


Ignore:
Timestamp:
Aug 29, 2011 11:24:18 AM (13 years ago)
Author:
andreas.kling@nokia.com
Message:

Viewing a post on reddit.com wastes a lot of memory on event listeners.
https://bugs.webkit.org/show_bug.cgi?id=67133

Reviewed by Darin Adler.

Source/JavaScriptCore:

Add a minimum table size to the HashTraits, instead of having it hard coded.
The default value remains at 64, but can now be specialized.

  • runtime/StructureTransitionTable.h:
  • wtf/HashTable.h:

(WTF::HashTable::shouldShrink):
(WTF::::expand):
(WTF::::checkTableConsistencyExceptSize):

  • wtf/HashTraits.h:

Source/WebCore:

Specialize the HashMap used to store registered listeners on an EventTarget
to have a minimum size of 32 (rather than the default 64.)
It's very rare for pages to register listeners for so many different events
and this cuts memory consumption in half for the common case.

As an example, for a typical post on the reddit.com front page,
this reduces memory used by ~700kB on 64-bit.

  • dom/EventTarget.h:
Location:
trunk/Source
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r93950 r93990  
     12011-08-29  Andreas Kling  <kling@webkit.org>
     2
     3        Viewing a post on reddit.com wastes a lot of memory on event listeners.
     4        https://bugs.webkit.org/show_bug.cgi?id=67133
     5
     6        Reviewed by Darin Adler.
     7
     8        Add a minimum table size to the HashTraits, instead of having it hard coded.
     9        The default value remains at 64, but can now be specialized.
     10
     11        * runtime/StructureTransitionTable.h:
     12        * wtf/HashTable.h:
     13        (WTF::HashTable::shouldShrink):
     14        (WTF::::expand):
     15        (WTF::::checkTableConsistencyExceptSize):
     16        * wtf/HashTraits.h:
     17
    1182011-08-28  Jonathan Liu  <net147@gmail.com>
    219
  • trunk/Source/JavaScriptCore/runtime/StructureTransitionTable.h

    r92810 r93990  
    6565
    6666        static const bool needsDestruction = FirstTraits::needsDestruction || SecondTraits::needsDestruction;
     67
     68        static const int minimumTableSize = FirstTraits::minimumTableSize;
    6769
    6870        static void constructDeletedValue(TraitType& slot) { FirstTraits::constructDeletedValue(slot.first); }
  • trunk/Source/JavaScriptCore/wtf/HashTable.h

    r84718 r93990  
    378378        bool shouldExpand() const { return (m_keyCount + m_deletedCount) * m_maxLoad >= m_tableSize; }
    379379        bool mustRehashInPlace() const { return m_keyCount * m_minLoad < m_tableSize * 2; }
    380         bool shouldShrink() const { return m_keyCount * m_minLoad < m_tableSize && m_tableSize > m_minTableSize; }
     380        bool shouldShrink() const { return m_keyCount * m_minLoad < m_tableSize && m_tableSize > KeyTraits::minimumTableSize; }
    381381        void expand();
    382382        void shrink() { rehash(m_tableSize / 2); }
     
    397397
    398398#if !ASSERT_DISABLED
    399         void checkTableConsistencyExceptSize() const;
     399        void checkTableConsistenmcyExceptSize() const;
    400400#else
    401401        static void checkTableConsistencyExceptSize() { }
     
    408408#endif
    409409
    410         static const int m_minTableSize = 64;
    411410        static const int m_maxLoad = 2;
    412411        static const int m_minLoad = 6;
     
    902901        int newSize;
    903902        if (m_tableSize == 0)
    904             newSize = m_minTableSize;
     903            newSize = KeyTraits::minimumTableSize;
    905904        else if (mustRehashInPlace())
    906905            newSize = m_tableSize;
     
    10401039        ASSERT(count == m_keyCount);
    10411040        ASSERT(deletedCount == m_deletedCount);
    1042         ASSERT(m_tableSize >= m_minTableSize);
     1041        ASSERT(m_tableSize >= KeyTraits::minimumTableSize);
    10431042        ASSERT(m_tableSizeMask);
    10441043        ASSERT(m_tableSize == m_tableSizeMask + 1);
  • trunk/Source/JavaScriptCore/wtf/HashTraits.h

    r83664 r93990  
    3939        static const bool emptyValueIsZero = false;
    4040        static const bool needsDestruction = true;
     41        static const int minimumTableSize = 64;
    4142    };
    4243
    4344    // Default integer traits disallow both 0 and -1 as keys (max value instead of -1 for unsigned).
    44     template<typename T> struct GenericHashTraitsBase<true, T> {
     45    template<typename T> struct GenericHashTraitsBase<true, T> : GenericHashTraitsBase<false, T> {
    4546        static const bool emptyValueIsZero = true;
    4647        static const bool needsDestruction = false;
     
    103104        static const bool needsDestruction = FirstTraits::needsDestruction || SecondTraits::needsDestruction;
    104105
     106        static const int minimumTableSize = FirstTraits::minimumTableSize;
     107
    105108        static void constructDeletedValue(TraitType& slot) { FirstTraits::constructDeletedValue(slot.first); }
    106109        static bool isDeletedValue(const TraitType& value) { return FirstTraits::isDeletedValue(value.first); }
  • trunk/Source/WebCore/ChangeLog

    r93988 r93990  
     12011-08-29  Andreas Kling  <kling@webkit.org>
     2
     3        Viewing a post on reddit.com wastes a lot of memory on event listeners.
     4        https://bugs.webkit.org/show_bug.cgi?id=67133
     5
     6        Reviewed by Darin Adler.
     7
     8        Specialize the HashMap used to store registered listeners on an EventTarget
     9        to have a minimum size of 32 (rather than the default 64.)
     10        It's very rare for pages to register listeners for so many different events
     11        and this cuts memory consumption in half for the common case.
     12
     13        As an example, for a typical post on the reddit.com front page,
     14        this reduces memory used by ~700kB on 64-bit.
     15
     16        * dom/EventTarget.h:
     17
    1182011-08-29  Stephen White  <senorblanco@chromium.org>
    219
  • trunk/Source/WebCore/dom/EventTarget.h

    r92304 r93990  
    8787
    8888    typedef Vector<RegisteredEventListener, 1> EventListenerVector;
    89     typedef HashMap<AtomicString, EventListenerVector*> EventListenerMap;
     89
     90    struct EventListenerMapHashTraits : HashTraits<WTF::AtomicString> {
     91        static const int minimumTableSize = 32;
     92    };
     93
     94    typedef HashMap<AtomicString, EventListenerVector*, AtomicStringHash, EventListenerMapHashTraits> EventListenerMap;
    9095
    9196    struct EventTargetData {
Note: See TracChangeset for help on using the changeset viewer.