Ignore:
Timestamp:
Jun 1, 2011, 1:09:04 PM (14 years ago)
Author:
[email protected]
Message:

2011-06-01 Oliver Hunt <[email protected]>

Reviewed by Geoffrey Garen.

Add single character lookup cache to IdentifierArena
https://bugs.webkit.org/show_bug.cgi?id=61879

Add a simple lookup cache for single ascii character
identifiers. Produces around a 2% improvement in parse
time for my adhoc parser test.

  • parser/ParserArena.h: (JSC::IdentifierArena::IdentifierArena): (JSC::IdentifierArena::clear): (JSC::IdentifierArena::makeIdentifier):
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/parser/ParserArena.h

    r76248 r87838  
    3838        WTF_MAKE_FAST_ALLOCATED;
    3939    public:
     40        IdentifierArena()
     41        {
     42            clear();
     43        }
     44
    4045        ALWAYS_INLINE const Identifier& makeIdentifier(JSGlobalData*, const UChar* characters, size_t length);
    4146        const Identifier& makeNumericIdentifier(JSGlobalData*, double number);
    4247
    43         void clear() { m_identifiers.clear(); }
     48        void clear()
     49        {
     50            m_identifiers.clear();
     51            for (unsigned  i = 0; i < 128; i++)
     52                m_shortIdentifiers[i] = 0;
     53        }
    4454        bool isEmpty() const { return m_identifiers.isEmpty(); }
    4555
    4656    private:
     57        static const int MaximumCachableCharacter = 128;
    4758        typedef SegmentedVector<Identifier, 64> IdentifierVector;
    4859        IdentifierVector m_identifiers;
     60        FixedArray<Identifier*, MaximumCachableCharacter> m_shortIdentifiers;
    4961    };
    5062
    5163    ALWAYS_INLINE const Identifier& IdentifierArena::makeIdentifier(JSGlobalData* globalData, const UChar* characters, size_t length)
    5264    {
     65        if (length == 1 && characters[0] < MaximumCachableCharacter) {
     66            if (Identifier* ident = m_shortIdentifiers[characters[0]])
     67                return *ident;
     68            m_identifiers.append(Identifier(globalData, characters, length));
     69            m_shortIdentifiers[characters[0]] = &m_identifiers.last();
     70            return m_identifiers.last();
     71        }
    5372        m_identifiers.append(Identifier(globalData, characters, length));
    5473        return m_identifiers.last();
Note: See TracChangeset for help on using the changeset viewer.