Changeset 201738 in webkit


Ignore:
Timestamp:
Jun 6, 2016 8:24:54 PM (8 years ago)
Author:
sbarati@apple.com
Message:

equal(StringView, StringView) for strings should have a fast path for pointer equality
https://bugs.webkit.org/show_bug.cgi?id=158452

Reviewed by Andreas Kling.

JSBench does a lot of StringView::operator== on StringViews that have
the same underlying characters pointer. This becomes hot inside JSBench
because JSBench heavily stresses JSC's UnlinkedCodeCache with a high
hit rate. This means that when we get a hit in the cache, we used to
do the long form of string compare. However, we were often comparing
two StringViews that had the same underlying buffer and length.
This patch speeds this case up to run in constant time instead of
linear time.

  • wtf/text/StringCommon.h:

(WTF::equalCommon):

  • wtf/text/StringImpl.h:

(WTF::StringImpl::StringImpl):
(WTF::StringImpl::data):

  • wtf/text/StringView.h:

(WTF::StringView::data):

Location:
trunk/Source/WTF
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r201684 r201738  
     12016-06-06  Saam Barati  <sbarati@apple.com>
     2
     3        equal(StringView, StringView) for strings should have a fast path for pointer equality
     4        https://bugs.webkit.org/show_bug.cgi?id=158452
     5
     6        Reviewed by Andreas Kling.
     7
     8        JSBench does a lot of StringView::operator== on StringViews that have
     9        the same underlying characters pointer. This becomes hot inside JSBench
     10        because JSBench heavily stresses JSC's UnlinkedCodeCache with a high
     11        hit rate. This means that when we get a hit in the cache, we used to
     12        do the long form of string compare. However, we were often comparing
     13        two StringViews that had the same underlying buffer and length.
     14        This patch speeds this case up to run in constant time instead of
     15        linear time.
     16
     17        * wtf/text/StringCommon.h:
     18        (WTF::equalCommon):
     19        * wtf/text/StringImpl.h:
     20        (WTF::StringImpl::StringImpl):
     21        (WTF::StringImpl::data):
     22        * wtf/text/StringView.h:
     23        (WTF::StringView::data):
     24
    1252016-06-04  Anders Carlsson  <andersca@apple.com>
    226
  • trunk/Source/WTF/wtf/text/StringView.h

    r196080 r201738  
    136136
    137137private:
     138    friend bool equal(StringView, StringView);
     139
    138140    void initialize(const LChar*, unsigned length);
    139141    void initialize(const UChar*, unsigned length);
     
    526528inline bool equal(StringView a, StringView b)
    527529{
     530    if (a.m_characters == b.m_characters) {
     531        ASSERT(a.is8Bit() == b.is8Bit());
     532        return a.length() == b.length();
     533    }
     534       
    528535    return equalCommon(a, b);
    529536}
Note: See TracChangeset for help on using the changeset viewer.