Ignore:
Timestamp:
Mar 24, 2010, 12:11:51 AM (15 years ago)
Author:
[email protected]
Message:

Bug 36519 - JSGlobalContextRelease is unnecessarily slow

Reviewed by Oliver Hunt.

Since [ http://trac.webkit.org/changeset/35917 ], calling
JSGlobalContextRelease always triggers a GC heap collection
(if not a full destroy). As per 35917's changelog "This is
only really necessary when the (JSGlobalObject's) last
reference is released, but there is no way to determine that,
and no harm in collecting slightly more often."

Well, we now know of cases of API clients who are harmed by
the performance penalty of collecting too often, so it's time
to add a way to determine whether a call to JSGlobalContextRelease
is removing the last protect from it's global object. If further
protects are retaining the global object (likely from other
JSGlobalContextRefs), then don't trigger a GC collection.

  • API/JSContextRef.cpp:
  • runtime/Collector.cpp:

(JSC::Heap::unprotect): return a boolean indicating that the value is now unprotected.

  • runtime/Collector.h:
  • wtf/HashCountedSet.h:

(WTF::::remove): return a boolean indicating whether the value was removed from the set.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/wtf/HashCountedSet.h

    r48732 r56435  
    4444        bool isEmpty() const;
    4545       
    46         // iterators iterate over pairs of values and counts
     46        // Iterators iterate over pairs of values and counts.
    4747        iterator begin();
    4848        iterator end();
     
    5555        unsigned count(const ValueType&) const;
    5656
    57         // increases the count if an equal value is already present
    58         // the return value is a pair of an interator to the new value's location,
    59         // and a bool that is true if an new entry was added
     57        // Increases the count if an equal value is already present
     58        // the return value is a pair of an interator to the new value's
     59        // location, and a bool that is true if an new entry was added.
    6060        std::pair<iterator, bool> add(const ValueType&);
    6161       
    62         // reduces the count of the value, and removes it if count
    63         // goes down to zero
    64         void remove(const ValueType&);
    65         void remove(iterator);
     62        // Reduces the count of the value, and removes it if count
     63        // goes down to zero, returns true if the value is removed.
     64        bool remove(const ValueType&);
     65        bool remove(iterator);
    6666 
    67         // removes the value, regardless of its count
     67        // Removes the value, regardless of its count.
    6868        void removeAll(iterator);
    6969        void removeAll(const ValueType&);
    7070
    71         // clears the whole set
     71        // Clears the whole set.
    7272        void clear();
    7373
     
    151151   
    152152    template<typename Value, typename HashFunctions, typename Traits>
    153     inline void HashCountedSet<Value, HashFunctions, Traits>::remove(const ValueType& value)
    154     {
    155         remove(find(value));
    156     }
    157    
    158     template<typename Value, typename HashFunctions, typename Traits>
    159     inline void HashCountedSet<Value, HashFunctions, Traits>::remove(iterator it)
     153    inline bool HashCountedSet<Value, HashFunctions, Traits>::remove(const ValueType& value)
     154    {
     155        return remove(find(value));
     156    }
     157   
     158    template<typename Value, typename HashFunctions, typename Traits>
     159    inline bool HashCountedSet<Value, HashFunctions, Traits>::remove(iterator it)
    160160    {
    161161        if (it == end())
    162             return;
     162            return false;
    163163
    164164        unsigned oldVal = it->second;
    165         ASSERT(oldVal != 0);
     165        ASSERT(oldVal);
    166166        unsigned newVal = oldVal - 1;
    167         if (newVal == 0)
    168             m_impl.remove(it);
    169         else
     167        if (newVal) {
    170168            it->second = newVal;
     169            return false;
     170        }
     171
     172        m_impl.remove(it);
     173        return true;
    171174    }
    172175   
Note: See TracChangeset for help on using the changeset viewer.