Title: [87838] trunk/Source/_javascript_Core
Revision
87838
Author
[email protected]
Date
2011-06-01 13:09:04 -0700 (Wed, 01 Jun 2011)

Log 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):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (87837 => 87838)


--- trunk/Source/_javascript_Core/ChangeLog	2011-06-01 19:52:13 UTC (rev 87837)
+++ trunk/Source/_javascript_Core/ChangeLog	2011-06-01 20:09:04 UTC (rev 87838)
@@ -1,3 +1,19 @@
+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):
+
 2011-05-31  Oliver Hunt  <[email protected]>
 
         Reviewed by Geoffrey Garen.

Modified: trunk/Source/_javascript_Core/parser/ParserArena.h (87837 => 87838)


--- trunk/Source/_javascript_Core/parser/ParserArena.h	2011-06-01 19:52:13 UTC (rev 87837)
+++ trunk/Source/_javascript_Core/parser/ParserArena.h	2011-06-01 20:09:04 UTC (rev 87838)
@@ -37,19 +37,38 @@
     class IdentifierArena {
         WTF_MAKE_FAST_ALLOCATED;
     public:
+        IdentifierArena()
+        {
+            clear();
+        }
+
         ALWAYS_INLINE const Identifier& makeIdentifier(JSGlobalData*, const UChar* characters, size_t length);
         const Identifier& makeNumericIdentifier(JSGlobalData*, double number);
 
-        void clear() { m_identifiers.clear(); }
+        void clear()
+        {
+            m_identifiers.clear();
+            for (unsigned  i = 0; i < 128; i++)
+                m_shortIdentifiers[i] = 0;
+        }
         bool isEmpty() const { return m_identifiers.isEmpty(); }
 
     private:
+        static const int MaximumCachableCharacter = 128;
         typedef SegmentedVector<Identifier, 64> IdentifierVector;
         IdentifierVector m_identifiers;
+        FixedArray<Identifier*, MaximumCachableCharacter> m_shortIdentifiers;
     };
 
     ALWAYS_INLINE const Identifier& IdentifierArena::makeIdentifier(JSGlobalData* globalData, const UChar* characters, size_t length)
     {
+        if (length == 1 && characters[0] < MaximumCachableCharacter) {
+            if (Identifier* ident = m_shortIdentifiers[characters[0]])
+                return *ident;
+            m_identifiers.append(Identifier(globalData, characters, length));
+            m_shortIdentifiers[characters[0]] = &m_identifiers.last();
+            return m_identifiers.last();
+        }
         m_identifiers.append(Identifier(globalData, characters, length));
         return m_identifiers.last();
     }
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to