Changeset 36124 in webkit for trunk/JavaScriptCore


Ignore:
Timestamp:
Sep 5, 2008, 9:58:40 PM (17 years ago)
Author:
Darin Adler
Message:

2008-09-05 Darin Adler <Darin Adler>

Reviewed by Geoff Garen.

1.007x as fast on SunSpider overall
1.167x as fast on SunSpider string/fasta

  • JavaScriptCore.exp: Updated.
  • kjs/SmallStrings.cpp: (KJS::SmallStrings::singleCharacterStringRep): Added.
  • kjs/SmallStrings.h: Added singleCharacterStringRep for clients that need just a UString, not a JSString.
  • kjs/identifier.cpp: (KJS::Identifier::add): Added special cases for single character strings so that the UString::Rep that ends up in the identifier table is the one from the single-character string optimization; otherwise we end up having to look it up in the identifier table over and over again. (KJS::Identifier::addSlowCase): Ditto. (KJS::Identifier::checkSameIdentifierTable): Made this function an empty inline in release builds so that callers don't have to put #ifndef NDEBUG at each call site.
  • kjs/identifier.h: (KJS::Identifier::add): Removed #ifndef NDEBUG around the calls to checkSameIdentifierTable. (KJS::Identifier::checkSameIdentifierTable): Added. Empty inline version for NDEBUG builds.
Location:
trunk/JavaScriptCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r36122 r36124  
     12008-09-05  Darin Adler  <[email protected]>
     2
     3        Reviewed by Geoff Garen.
     4
     5        - fix https://bugs.webkit.org/show_bug.cgi?id=20673
     6          single-character strings are churning in the Identifier table
     7
     8        1.007x as fast on SunSpider overall
     9        1.167x as fast on SunSpider string/fasta
     10
     11        * JavaScriptCore.exp: Updated.
     12        * kjs/SmallStrings.cpp:
     13        (KJS::SmallStrings::singleCharacterStringRep): Added.
     14        * kjs/SmallStrings.h: Added singleCharacterStringRep for clients that
     15        need just a UString, not a JSString.
     16        * kjs/identifier.cpp:
     17        (KJS::Identifier::add): Added special cases for single character strings
     18        so that the UString::Rep that ends up in the identifier table is the one
     19        from the single-character string optimization; otherwise we end up having
     20        to look it up in the identifier table over and over again.
     21        (KJS::Identifier::addSlowCase): Ditto.
     22        (KJS::Identifier::checkSameIdentifierTable): Made this function an empty
     23        inline in release builds so that callers don't have to put #ifndef NDEBUG
     24        at each call site.
     25        * kjs/identifier.h:
     26        (KJS::Identifier::add): Removed #ifndef NDEBUG around the calls to
     27        checkSameIdentifierTable.
     28        (KJS::Identifier::checkSameIdentifierTable): Added. Empty inline version
     29        for NDEBUG builds.
     30
    1312008-09-05  Mark Rowe  <[email protected]>
    232
  • trunk/JavaScriptCore/JavaScriptCore.exp

    r36068 r36124  
    8787__ZN3KJS10Identifier11addSlowCaseEPNS_12JSGlobalDataEPNS_7UString3RepE
    8888__ZN3KJS10Identifier11addSlowCaseEPNS_9ExecStateEPNS_7UString3RepE
    89 __ZN3KJS10Identifier24checkSameIdentifierTableEPNS_12JSGlobalDataEPNS_7UString3RepE
    90 __ZN3KJS10Identifier24checkSameIdentifierTableEPNS_9ExecStateEPNS_7UString3RepE
    9189__ZN3KJS10Identifier3addEPNS_9ExecStateEPKc
    9290__ZN3KJS10Identifier5equalEPKNS_7UString3RepEPKc
  • trunk/JavaScriptCore/kjs/SmallStrings.cpp

    r36006 r36124  
    102102}
    103103
     104UString::Rep* SmallStrings::singleCharacterStringRep(unsigned char character)
     105{
     106    if (!m_storage)
     107        m_storage.set(new SmallStringsStorage);
     108    return m_storage->rep(character);
    104109}
     110
     111}
  • trunk/JavaScriptCore/kjs/SmallStrings.h

    r36006 r36124  
    2727#define SmallStrings_h
    2828
     29#include "ustring.h"
    2930#include <wtf/OwnPtr.h>
    3031
     
    5354            return m_singleCharacterStrings[character];
    5455        }
     56
     57        UString::Rep* singleCharacterStringRep(unsigned char character);
    5558       
    5659        void mark();
  • trunk/JavaScriptCore/kjs/identifier.cpp

    r35898 r36124  
    130130        return &UString::Rep::null;
    131131    }
    132 
    133132    if (!c[0]) {
    134133        UString::Rep::empty.hash();
    135134        return &UString::Rep::empty;
    136135    }
     136    if (!c[1])
     137        return add(globalData, globalData->smallStrings.singleCharacterStringRep(static_cast<unsigned char>(c[0])));
    137138
    138139    IdentifierTable& identifierTable = *globalData->identifierTable;
     
    187188PassRefPtr<UString::Rep> Identifier::add(JSGlobalData* globalData, const UChar* s, int length)
    188189{
     190    if (length == 1) {
     191        UChar c = s[0];
     192        if (c <= 0xFF)
     193            return add(globalData, globalData->smallStrings.singleCharacterStringRep(c));
     194    }
    189195    if (!length) {
    190196        UString::Rep::empty.hash();
    191197        return &UString::Rep::empty;
    192198    }
    193    
    194199    UCharBuffer buf = {s, length};
    195200    return *globalData->identifierTable->add<UCharBuffer, UCharBufferTranslator>(buf).first;
     
    204209{
    205210    ASSERT(!r->identifierTable());
    206 
    207     if (r->len == 0) {
     211    if (r->len == 1) {
     212        UChar c = r->data()[0];
     213        if (c <= 0xFF)
     214            r = globalData->smallStrings.singleCharacterStringRep(c);
     215            if (r->identifierTable()) {
     216                checkSameIdentifierTable(globalData, r);
     217                return r;
     218            }
     219    }
     220    if (!r->len) {
    208221        UString::Rep::empty.hash();
    209222        return &UString::Rep::empty;
    210223    }
    211 
    212224    return *globalData->identifierTable->add(r).first;
    213225}
     
    224236
    225237#ifndef NDEBUG
     238
    226239void Identifier::checkSameIdentifierTable(ExecState* exec, UString::Rep* rep)
    227240{
     
    233246    ASSERT(rep->identifierTable() == globalData->identifierTable);
    234247}
    235 #else
    236 void Identifier::checkSameIdentifierTable(ExecState*, UString::Rep*)
    237 {
    238 }
    239 
    240 void Identifier::checkSameIdentifierTable(JSGlobalData*, UString::Rep*)
    241 {
    242 }
     248
    243249#endif
    244250
  • trunk/JavaScriptCore/kjs/identifier.h

    r35776 r36124  
    9393        {
    9494            if (r->identifierTable()) {
    95 #ifndef NDEBUG
    9695                checkSameIdentifierTable(exec, r);
    97 #endif
    9896                return r;
    9997            }
     
    103101        {
    104102            if (r->identifierTable()) {
    105 #ifndef NDEBUG
    106103                checkSameIdentifierTable(globalData, r);
    107 #endif
    108104                return r;
    109105            }
     
    136132    void deleteIdentifierTable(IdentifierTable*);
    137133
     134#ifdef NDEBUG
     135    inline void Identifier::checkSameIdentifierTable(ExecState*, UString::Rep*) { }
     136    inline void Identifier::checkSameIdentifierTable(JSGlobalData*, UString::Rep*) { }
     137#endif
     138
    138139} // namespace KJS
    139140
Note: See TracChangeset for help on using the changeset viewer.