Ignore:
Timestamp:
Oct 31, 2007, 1:22:12 AM (18 years ago)
Author:
mjs
Message:

Reviewed by ChangeLog.


  • get rid of integer divide in PropertyMap and HashTable for 1% SunSpider speedup


Integer divide sucks. Fortunately, a bunch of shifts and XORs
biased towards the high bits is sufficient to provide a good
double hash. Besides the SunSpider win, I used the dump statistics
mode for both to verify that collisions did not increase and that
the longest collision chain is not any longer.

  • kjs/property_map.cpp: (KJS::doubleHash): (KJS::PropertyMap::get): (KJS::PropertyMap::getLocation): (KJS::PropertyMap::put): (KJS::PropertyMap::insert): (KJS::PropertyMap::remove): (KJS::PropertyMap::checkConsistency):
  • wtf/HashTable.h: (WTF::doubleHash): (WTF::::lookup): (WTF::::lookupForWriting): (WTF::::fullLookupForWriting): (WTF::::add):
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/property_map.cpp

    r27127 r27301  
    2626#include "protect.h"
    2727#include "PropertyNameArray.h"
     28#include "HashTable.h"
    2829#include <algorithm>
    2930#include <wtf/Assertions.h>
     
    3536#define DEBUG_PROPERTIES 0
    3637#define DO_CONSISTENCY_CHECK 0
    37 #define DUMP_STATISTICS 0
     38#define DUMP_PROPERTYMAP_STATS 0
    3839#define USE_SINGLE_ENTRY 1
    3940
     
    5152const int smallMapThreshold = 1024;
    5253
    53 #if DUMP_STATISTICS
     54#if DUMP_PROPERTYMAP_STATS
    5455
    5556static int numProbes;
     
    181182    int i = h & sizeMask;
    182183    int k = 0;
    183 #if DUMP_STATISTICS
     184#if DUMP_PROPERTYMAP_STATS
    184185    ++numProbes;
    185186    numCollisions += entries[i].key && entries[i].key != rep;
     
    197198       
    198199        if (k == 0)
    199             k = 1 | (h % sizeMask);
     200            k = 1 | doubleHash(h);
    200201        i = (i + k) & sizeMask;
    201 #if DUMP_STATISTICS
     202#if DUMP_PROPERTYMAP_STATS
    202203        ++numRehashes;
    203204#endif
     
    225226    int i = h & sizeMask;
    226227    int k = 0;
    227 #if DUMP_STATISTICS
     228#if DUMP_PROPERTYMAP_STATS
    228229    ++numProbes;
    229230    numCollisions += entries[i].key && entries[i].key != rep;
     
    239240       
    240241        if (k == 0)
    241             k = 1 | (h % sizeMask);
     242            k = 1 | doubleHash(h);
    242243        i = (i + k) & sizeMask;
    243 #if DUMP_STATISTICS
     244#if DUMP_PROPERTYMAP_STATS
    244245        ++numRehashes;
    245246#endif
     
    267268    int i = h & sizeMask;
    268269    int k = 0;
    269 #if DUMP_STATISTICS
     270#if DUMP_PROPERTYMAP_STATS
    270271    ++numProbes;
    271272    numCollisions += entries[i].key && entries[i].key != rep;
     
    281282       
    282283        if (k == 0)
    283             k = 1 | (h % sizeMask);
     284            k = 1 | doubleHash(h);
    284285        i = (i + k) & sizeMask;
    285 #if DUMP_STATISTICS
     286#if DUMP_PROPERTYMAP_STATS
    286287        ++numRehashes;
    287288#endif
     
    353354    bool foundDeletedElement = false;
    354355    int deletedElementIndex = 0;    /* initialize to make the compiler happy */
    355 #if DUMP_STATISTICS
     356#if DUMP_PROPERTYMAP_STATS
    356357    ++numProbes;
    357358    numCollisions += entries[i].key && entries[i].key != rep;
     
    372373        }
    373374        if (k == 0)
    374             k = 1 | (h % sizeMask);
     375            k = 1 | doubleHash(h);
    375376        i = (i + k) & sizeMask;
    376 #if DUMP_STATISTICS
     377#if DUMP_PROPERTYMAP_STATS
    377378        ++numRehashes;
    378379#endif
     
    405406    int i = h & sizeMask;
    406407    int k = 0;
    407 #if DUMP_STATISTICS
     408#if DUMP_PROPERTYMAP_STATS
    408409    ++numProbes;
    409410    numCollisions += entries[i].key && entries[i].key != key;
     
    412413        ASSERT(entries[i].key != deletedSentinel());
    413414        if (k == 0)
    414             k = 1 | (h % sizeMask);
     415            k = 1 | doubleHash(h);
    415416        i = (i + k) & sizeMask;
    416 #if DUMP_STATISTICS
     417#if DUMP_PROPERTYMAP_STATS
    417418        ++numRehashes;
    418419#endif
     
    532533    int i = h & sizeMask;
    533534    int k = 0;
    534 #if DUMP_STATISTICS
     535#if DUMP_PROPERTYMAP_STATS
    535536    ++numProbes;
    536537    ++numRemoves;
     
    541542            break;
    542543        if (k == 0)
    543             k = 1 | (h % sizeMask);
     544            k = 1 | doubleHash(h);
    544545        i = (i + k) & sizeMask;
    545 #if DUMP_STATISTICS
     546#if DUMP_PROPERTYMAP_STATS
    546547        ++numRehashes;
    547548#endif
     
    751752                break;
    752753            if (k == 0)
    753                 k = 1 | (h % m_u.table->sizeMask);
     754                k = 1 | doubleHash(h);
    754755            i = (i + k) & m_u.table->sizeMask;
    755756        }
Note: See TracChangeset for help on using the changeset viewer.