Changeset 87838 in webkit


Ignore:
Timestamp:
Jun 1, 2011 1:09:04 PM (13 years ago)
Author:
oliver@apple.com
Message:

2011-06-01 Oliver Hunt <oliver@apple.com>

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):
Location:
trunk/Source/JavaScriptCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r87826 r87838  
     12011-06-01  Oliver Hunt  <oliver@apple.com>
     2
     3        Reviewed by Geoffrey Garen.
     4
     5        Add single character lookup cache to IdentifierArena
     6        https://bugs.webkit.org/show_bug.cgi?id=61879
     7
     8        Add a simple lookup cache for single ascii character
     9        identifiers.  Produces around a 2% improvement in parse
     10        time for my adhoc parser test.
     11
     12        * parser/ParserArena.h:
     13        (JSC::IdentifierArena::IdentifierArena):
     14        (JSC::IdentifierArena::clear):
     15        (JSC::IdentifierArena::makeIdentifier):
     16
    1172011-05-31  Oliver Hunt  <oliver@apple.com>
    218
  • 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.