Changeset 55599 in webkit


Ignore:
Timestamp:
Mar 5, 2010 3:29:13 PM (14 years ago)
Author:
oliver@apple.com
Message:

2010-03-05 Oliver Hunt <oliver@apple.com>

Reviewed by Gavin Barraclough.

JSC should cache int to Identifier conversion as it does for ordinary strings
https://bugs.webkit.org/show_bug.cgi?id=35814

Make the NumericStrings cache cache unsigned ints in addition to signed.
We keep them separate from the int cache as it both simplifies code, and
also because the unsigned path is exclusive to property access and therefore
seems to have different usage patterns.

The primary trigger for the unsigned to Identifier propertyName conversion
is the construction of array-like objects out of normal objects. Given these
tend to be relative small numbers, and the array-like behaviour lends itself
to sequential values this patch also adds a non-colliding cache for all small
numbers.

  • JavaScriptCore.exp:
  • runtime/Identifier.cpp: (JSC::Identifier::from):
  • runtime/Identifier.h:
  • runtime/NumericStrings.h: (JSC::NumericStrings::add): (JSC::NumericStrings::lookup): (JSC::NumericStrings::lookupSmallString):
Location:
trunk/JavaScriptCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r55564 r55599  
     12010-03-05  Oliver Hunt  <oliver@apple.com>
     2
     3        Reviewed by Gavin Barraclough.
     4
     5        JSC should cache int to Identifier conversion as it does for ordinary strings
     6        https://bugs.webkit.org/show_bug.cgi?id=35814
     7
     8        Make the NumericStrings cache cache unsigned ints in addition to signed.
     9        We keep them separate from the int cache as it both simplifies code, and
     10        also because the unsigned path is exclusive to property access and therefore
     11        seems to have different usage patterns.
     12
     13        The primary trigger for the unsigned to Identifier propertyName conversion
     14        is the construction of array-like objects out of normal objects.  Given these
     15        tend to be relative small numbers, and the array-like behaviour lends itself
     16        to sequential values this patch also adds a non-colliding cache for all small
     17        numbers.
     18
     19        * JavaScriptCore.exp:
     20        * runtime/Identifier.cpp:
     21        (JSC::Identifier::from):
     22        * runtime/Identifier.h:
     23        * runtime/NumericStrings.h:
     24        (JSC::NumericStrings::add):
     25        (JSC::NumericStrings::lookup):
     26        (JSC::NumericStrings::lookupSmallString):
     27
    1282010-03-03  Oliver Hunt  <oliver@apple.com>
    229
  • trunk/JavaScriptCore/JavaScriptCore.exp

    r55401 r55599  
    9696__ZN3JSC10Identifier24checkSameIdentifierTableEPNS_9ExecStateEPNS_11UStringImplE
    9797__ZN3JSC10Identifier3addEPNS_9ExecStateEPKc
     98__ZN3JSC10Identifier4fromEPNS_9ExecStateEi
     99__ZN3JSC10Identifier4fromEPNS_9ExecStateEj
    98100__ZN3JSC10Identifier5equalEPKNS_11UStringImplEPKc
    99101__ZN3JSC10JSFunctionC1EPNS_9ExecStateEN3WTF17NonNullPassRefPtrINS_9StructureEEEiRKNS_10IdentifierEPFNS_7JSValueES2_PNS_8JSObjectESA_RKNS_7ArgListEE
  • trunk/JavaScriptCore/runtime/Identifier.cpp

    r54843 r55599  
    2323
    2424#include "CallFrame.h"
     25#include "NumericStrings.h"
    2526#include <new> // for placement new
    2627#include <string.h> // for strlen
     
    237238    currentIdentifierTable()->remove(r);
    238239}
     240   
     241Identifier Identifier::from(ExecState* exec, unsigned value)
     242{
     243    return Identifier(exec, exec->globalData().numericStrings.add(value));
     244}
     245
     246Identifier Identifier::from(ExecState* exec, int value)
     247{
     248    return Identifier(exec, exec->globalData().numericStrings.add(value));
     249}
     250
     251Identifier Identifier::from(ExecState* exec, double value)
     252{
     253    return Identifier(exec, exec->globalData().numericStrings.add(value));
     254}
    239255
    240256#ifndef NDEBUG
  • trunk/JavaScriptCore/runtime/Identifier.h

    r54789 r55599  
    5555        const char* ascii() const { return _ustring.ascii(); }
    5656       
    57         static Identifier from(ExecState* exec, unsigned y) { return Identifier(exec, UString::from(y)); }
    58         static Identifier from(ExecState* exec, int y) { return Identifier(exec, UString::from(y)); }
    59         static Identifier from(ExecState* exec, double y) { return Identifier(exec, UString::from(y)); }
     57        static Identifier from(ExecState* exec, unsigned y);
     58        static Identifier from(ExecState* exec, int y);
     59        static Identifier from(ExecState* exec, double y);
    6060       
    6161        bool isNull() const { return _ustring.isNull(); }
  • trunk/JavaScriptCore/runtime/NumericStrings.h

    r47622 r55599  
    4646        UString add(int i)
    4747        {
     48            if (static_cast<unsigned>(i) < cacheSize)
     49                return lookupSmallString(static_cast<unsigned>(i));
    4850            CacheEntry<int>& entry = lookup(i);
    4951            if (i == entry.key && !entry.value.isNull())
     
    5456        }
    5557
     58        UString add(unsigned i)
     59        {
     60            if (i < cacheSize)
     61                return lookupSmallString(static_cast<unsigned>(i));
     62            CacheEntry<unsigned>& entry = lookup(i);
     63            if (i == entry.key && !entry.value.isNull())
     64                return entry.value;
     65            entry.key = i;
     66            entry.value = UString::from(i);
     67            return entry.value;
     68        }
    5669    private:
    5770        static const size_t cacheSize = 64;
     
    6578        CacheEntry<double>& lookup(double d) { return doubleCache[WTF::FloatHash<double>::hash(d) & (cacheSize - 1)]; }
    6679        CacheEntry<int>& lookup(int i) { return intCache[WTF::IntHash<int>::hash(i) & (cacheSize - 1)]; }
     80        CacheEntry<unsigned>& lookup(unsigned i) { return unsignedCache[WTF::IntHash<unsigned>::hash(i) & (cacheSize - 1)]; }
     81        const UString& lookupSmallString(unsigned i)
     82        {
     83            ASSERT(i < cacheSize);
     84            if (smallIntCache[i].isNull())
     85                smallIntCache[i] = UString::from(i);
     86            return smallIntCache[i];
     87        }
    6788
    6889        CacheEntry<double> doubleCache[cacheSize];
    6990        CacheEntry<int> intCache[cacheSize];
     91        CacheEntry<unsigned> unsignedCache[cacheSize];
     92        UString smallIntCache[cacheSize];
    7093    };
    7194
Note: See TracChangeset for help on using the changeset viewer.