Changeset 37627 in webkit for trunk/JavaScriptCore


Ignore:
Timestamp:
Oct 15, 2008, 9:36:12 PM (17 years ago)
Author:
[email protected]
Message:

2008-10-15 Cameron Zwarich <[email protected]>

Reviewed by Maciej Stachowiak.

Bug 21633: Avoid using a HashMap when there is only a single transition
<https://bugs.webkit.org/show_bug.cgi?id=21633>

This is a 0.8% speedup on SunSpider and between a 0.5% and 1.0% speedup
on the V8 benchmark suite, depending on which harness we use. It will
also slightly reduce the memory footprint of a StructureID.

  • kjs/StructureID.cpp: (JSC::StructureID::StructureID): (JSC::StructureID::~StructureID): (JSC::StructureID::addPropertyTransition):
  • kjs/StructureID.h: (JSC::StructureID::):
Location:
trunk/JavaScriptCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r37625 r37627  
     12008-10-15  Cameron Zwarich  <[email protected]>
     2
     3        Reviewed by Maciej Stachowiak.
     4
     5        Bug 21633: Avoid using a HashMap when there is only a single transition
     6        <https://bugs.webkit.org/show_bug.cgi?id=21633>
     7
     8        This is a 0.8% speedup on SunSpider and between a 0.5% and 1.0% speedup
     9        on the V8 benchmark suite, depending on which harness we use. It will
     10        also slightly reduce the memory footprint of a StructureID.
     11
     12        * kjs/StructureID.cpp:
     13        (JSC::StructureID::StructureID):
     14        (JSC::StructureID::~StructureID):
     15        (JSC::StructureID::addPropertyTransition):
     16        * kjs/StructureID.h:
     17        (JSC::StructureID::):
     18
    1192008-10-15  Csaba Osztrogonac  <[email protected]>
    220
  • trunk/JavaScriptCore/kjs/StructureID.cpp

    r37563 r37627  
    5454    , m_nameInPrevious(0)
    5555    , m_transitionCount(0)
     56    , m_usingSingleTransitionSlot(true)
    5657    , m_propertyStorageCapacity(JSObject::inlineStorageCapacity)
    5758    , m_cachedTransistionOffset(WTF::notFound)
     
    5960    ASSERT(m_prototype);
    6061    ASSERT(m_prototype->isObject() || m_prototype->isNull());
     62
     63    m_transitions.singleTransition = 0;
    6164
    6265#ifndef NDEBUG
     
    7174{
    7275    if (m_previous) {
    73         ASSERT(m_previous->m_transitionTable.contains(make_pair(m_nameInPrevious, m_attributesInPrevious)));
    74         m_previous->m_transitionTable.remove(make_pair(m_nameInPrevious, m_attributesInPrevious));
     76        if (m_previous->m_usingSingleTransitionSlot) {
     77            m_previous->m_transitions.singleTransition->deref();
     78            m_previous->m_transitions.singleTransition = 0;
     79        } else {
     80            ASSERT(m_previous->m_transitions.table->contains(make_pair(m_nameInPrevious, m_attributesInPrevious)));
     81            m_previous->m_transitions.table->remove(make_pair(m_nameInPrevious, m_attributesInPrevious));
     82        }
    7583    }
    7684
    7785    if (m_cachedPropertyNameArrayData)
    7886        m_cachedPropertyNameArrayData->setCachedStructureID(0);
     87
     88    if (m_usingSingleTransitionSlot) {
     89        if (m_transitions.singleTransition)
     90            m_transitions.singleTransition->deref();
     91    } else
     92        delete m_transitions.table;
    7993
    8094#ifndef NDEBUG
     
    169183    ASSERT(structureID->typeInfo().type() == ObjectType);
    170184
    171     if (StructureID* existingTransition = structureID->m_transitionTable.get(make_pair(propertyName.ustring().rep(), attributes))) {
    172         offset = existingTransition->cachedTransistionOffset();
    173         ASSERT(offset != WTF::notFound);
    174         return existingTransition;
     185    if (structureID->m_usingSingleTransitionSlot) {
     186        StructureID* existingTransition = structureID->m_transitions.singleTransition;
     187        if (existingTransition && existingTransition->m_nameInPrevious == propertyName.ustring().rep() && existingTransition->m_attributesInPrevious == attributes) {
     188            offset = structureID->m_transitions.singleTransition->cachedTransistionOffset();
     189            ASSERT(offset != WTF::notFound);
     190            return existingTransition;
     191        }
     192    } else {
     193        if (StructureID* existingTransition = structureID->m_transitions.table->get(make_pair(propertyName.ustring().rep(), attributes))) {
     194            offset = existingTransition->cachedTransistionOffset();
     195            ASSERT(offset != WTF::notFound);
     196            return existingTransition;
     197        }       
    175198    }
    176199
     
    199222    transition->setCachedTransistionOffset(offset);
    200223
    201     structureID->m_transitionTable.add(make_pair(propertyName.ustring().rep(), attributes), transition.get());
     224    if (structureID->m_usingSingleTransitionSlot) {
     225        if (!structureID->m_transitions.singleTransition) {
     226            structureID->m_transitions.singleTransition = transition.get();
     227            transition->ref();
     228            return transition.release();
     229        }
     230
     231        StructureID* existingTransition = structureID->m_transitions.singleTransition;
     232        structureID->m_usingSingleTransitionSlot = false;
     233        TransitionTable* transitionTable = new TransitionTable;
     234        structureID->m_transitions.table = transitionTable;
     235        transitionTable->add(make_pair(existingTransition->m_nameInPrevious, existingTransition->m_attributesInPrevious), existingTransition);
     236        existingTransition->deref();
     237    }
     238    structureID->m_transitions.table->add(make_pair(propertyName.ustring().rep(), attributes), transition.get());
    202239    return transition.release();
    203240}
  • trunk/JavaScriptCore/kjs/StructureID.h

    r37563 r37627  
    153153
    154154        size_t m_transitionCount;
    155         TransitionTable m_transitionTable;
     155        bool m_usingSingleTransitionSlot;
     156        union {
     157            StructureID* singleTransition;
     158            TransitionTable* table;
     159        } m_transitions;
    156160
    157161        RefPtr<PropertyNameArrayData> m_cachedPropertyNameArrayData;
Note: See TracChangeset for help on using the changeset viewer.