Changeset 256011 in webkit


Ignore:
Timestamp:
Feb 7, 2020 12:55:58 AM (4 years ago)
Author:
ysuzuki@apple.com
Message:

Unreviewed, revert 75% load-factor because of JetStream2/string-unpack-code-SP regression
https://bugs.webkit.org/show_bug.cgi?id=207183

Source/WTF:

  • wtf/HashTable.h:

(WTF::HashTable::shouldExpand const):
(WTF::KeyTraits>::computeBestTableSize):
(WTF::HashTable::shouldExpand): Deleted.
(WTF::HashTableCapacityForSize::capacityForSize): Deleted.

Tools:

  • TestWebKitAPI/Tests/WTF/HashSet.cpp:

(TestWebKitAPI::testInitialCapacity):

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r256010 r256011  
     12020-02-07  Yusuke Suzuki  <ysuzuki@apple.com>
     2
     3        Unreviewed, revert 75% load-factor because of JetStream2/string-unpack-code-SP regression
     4        https://bugs.webkit.org/show_bug.cgi?id=207183
     5
     6        * wtf/HashTable.h:
     7        (WTF::HashTable::shouldExpand const):
     8        (WTF::KeyTraits>::computeBestTableSize):
     9        (WTF::HashTable::shouldExpand): Deleted.
     10        (WTF::HashTableCapacityForSize::capacityForSize): Deleted.
     11
    1122020-02-07  youenn fablet  <youenn@apple.com>
    213
  • trunk/Source/WTF/wtf/HashTable.h

    r255889 r256011  
    488488
    489489        static constexpr unsigned computeBestTableSize(unsigned keyCount);
    490         static constexpr bool shouldExpand(uint64_t keyAndDeleteCount, uint64_t tableSize)
    491         {
    492             return keyAndDeleteCount * maxLoadDenominator >= tableSize * maxLoadNumerator;
    493         }
    494         bool shouldExpand() const { return shouldExpand(keyCount() + deletedCount(), tableSize()); }
     490        bool shouldExpand() const { return (keyCount() + deletedCount()) * maxLoad >= tableSize(); }
    495491        bool mustRehashInPlace() const { return keyCount() * minLoad < tableSize() * 2; }
    496492        bool shouldShrink() const { return keyCount() * minLoad < tableSize() && tableSize() > KeyTraits::minimumTableSize; }
     
    527523#endif
    528524
    529         // Load-factor is 75%.
    530         static constexpr unsigned maxLoadNumerator = 3;
    531         static constexpr unsigned maxLoadDenominator = 4;
     525        static constexpr unsigned maxLoad = 2;
    532526        static constexpr unsigned minLoad = 6;
    533527
     
    563557    };
    564558
     559    // Set all the bits to one after the most significant bit: 00110101010 -> 00111111111.
     560    template<unsigned size> struct OneifyLowBits;
     561    template<>
     562    struct OneifyLowBits<0> {
     563        static constexpr unsigned value = 0;
     564    };
     565    template<unsigned number>
     566    struct OneifyLowBits {
     567        static constexpr unsigned value = number | OneifyLowBits<(number >> 1)>::value;
     568    };
     569    // Compute the first power of two integer that is an upper bound of the parameter 'number'.
     570    template<unsigned number>
     571    struct UpperPowerOfTwoBound {
     572        static constexpr unsigned value = (OneifyLowBits<number - 1>::value + 1) * 2;
     573    };
     574
     575    // Because power of two numbers are the limit of maxLoad, their capacity is twice the
     576    // UpperPowerOfTwoBound, or 4 times their values.
     577    template<unsigned size, bool isPowerOfTwo> struct HashTableCapacityForSizeSplitter;
     578    template<unsigned size>
     579    struct HashTableCapacityForSizeSplitter<size, true> {
     580        static constexpr unsigned value = size * 4;
     581    };
     582    template<unsigned size>
     583    struct HashTableCapacityForSizeSplitter<size, false> {
     584        static constexpr unsigned value = UpperPowerOfTwoBound<size>::value;
     585    };
     586
    565587    // HashTableCapacityForSize computes the upper power of two capacity to hold the size parameter.
    566588    // This is done at compile time to initialize the HashTraits.
    567589    template<unsigned size>
    568590    struct HashTableCapacityForSize {
    569         static constexpr unsigned capacityForSize(uint64_t sizeArg)
    570         {
    571             constexpr uint64_t maxLoadNumerator = 3;
    572             constexpr uint64_t maxLoadDenominator = 4;
    573             if (!sizeArg)
    574                 return 0;
    575             uint64_t capacity = roundUpToPowerOfTwo(sizeArg);
    576             if (sizeArg * maxLoadDenominator >= capacity * maxLoadNumerator)
    577                 return capacity * 2;
    578             return capacity;
    579         }
    580 
    581         static constexpr unsigned value = capacityForSize(size);
     591        static constexpr unsigned value = HashTableCapacityForSizeSplitter<size, !(size & (size - 1))>::value;
    582592        COMPILE_ASSERT(size > 0, HashTableNonZeroMinimumCapacity);
    583593        COMPILE_ASSERT(!static_cast<unsigned>(value >> 31), HashTableNoCapacityOverflow);
     594        COMPILE_ASSERT(value > (2 * size), HashTableCapacityHoldsContentSize);
    584595    };
    585596
     
    12281239        unsigned bestTableSize = WTF::roundUpToPowerOfTwo(keyCount) * 2;
    12291240
    1230         // With maxLoad at 3/4 and minLoad at 1/6, our average load is 11/24.
    1231         // If we are getting halfway between 11/24 and 3/4 (i.e. past 14.5/24,
    1232         // which we'll round up to 15/24 i.e. 5/8), we double the size to avoid
    1233         // being too close to loadMax and bring the ratio close to 11/24. This
    1234         // give us a load in the bounds [9/24, 15/24).
    1235         bool aboveThresholdForEagerExpansion = keyCount * 8 >= bestTableSize * 5;
    1236         if (aboveThresholdForEagerExpansion)
     1241        // With maxLoad at 1/2 and minLoad at 1/6, our average load is 2/6.
     1242        // If we are getting halfway between 2/6 and 1/2 (past 5/12), we double the size to avoid being too close to
     1243        // loadMax and bring the ratio close to 2/6. This give us a load in the bounds [3/12, 5/12).
     1244        bool aboveThreeQuarterLoad = keyCount * 12 >= bestTableSize * 5;
     1245        if (aboveThreeQuarterLoad)
    12371246            bestTableSize *= 2;
    12381247
  • trunk/Tools/ChangeLog

    r256000 r256011  
     12020-02-07  Yusuke Suzuki  <ysuzuki@apple.com>
     2
     3        Unreviewed, revert 75% load-factor because of JetStream2/string-unpack-code-SP regression
     4        https://bugs.webkit.org/show_bug.cgi?id=207183
     5
     6        * TestWebKitAPI/Tests/WTF/HashSet.cpp:
     7        (TestWebKitAPI::testInitialCapacity):
     8
    192020-02-06  Wenson Hsieh  <wenson_hsieh@apple.com>
    210
  • trunk/Tools/TestWebKitAPI/Tests/WTF/HashSet.cpp

    r255889 r256011  
    5656    }
    5757
    58     // Adding items up to less than 3/4 of the capacity should not change the capacity.
    59     unsigned capacityLimit = initialCapacity * 3 / 4 - 1;
     58    // Adding items up to less than half the capacity should not change the capacity.
     59    unsigned capacityLimit = initialCapacity / 2 - 1;
    6060    for (size_t i = size; i < capacityLimit; ++i) {
    6161        testSet.add(i);
Note: See TracChangeset for help on using the changeset viewer.