[webkit-changes] [WebKit/WebKit] 38bcd3: Optimize looking up keys by raw reference in hash ...

Chris Dumez noreply at github.com
Sun Dec 10 14:57:24 PST 2023


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 38bcd3245042be3cb678e0242a6ab95d4b1a9688
      https://github.com/WebKit/WebKit/commit/38bcd3245042be3cb678e0242a6ab95d4b1a9688
  Author: Chris Dumez <cdumez at apple.com>
  Date:   2023-12-10 (Sun, 10 Dec 2023)

  Changed paths:
    M Source/JavaScriptCore/bytecode/StructureStubInfo.h
    M Source/JavaScriptCore/jit/JITThunks.cpp
    M Source/JavaScriptCore/jit/JITThunks.h
    M Source/JavaScriptCore/runtime/Identifier.h
    M Source/WTF/wtf/CheckedPtr.h
    M Source/WTF/wtf/CheckedRef.h
    M Source/WTF/wtf/CompactPtr.h
    M Source/WTF/wtf/ConcurrentPtrHashSet.h
    M Source/WTF/wtf/GetPtr.h
    M Source/WTF/wtf/HashCountedSet.h
    M Source/WTF/wtf/HashFunctions.h
    M Source/WTF/wtf/HashMap.h
    M Source/WTF/wtf/HashSet.h
    M Source/WTF/wtf/ListHashSet.h
    M Source/WTF/wtf/Packed.h
    M Source/WTF/wtf/Ref.h
    M Source/WTF/wtf/RefPtr.h
    M Source/WTF/wtf/RetainPtr.h
    M Source/WTF/wtf/SchedulePair.h
    M Source/WTF/wtf/SignedPtr.h
    M Source/WTF/wtf/UniqueRef.h
    M Source/WTF/wtf/WeakPtr.h
    M Source/WTF/wtf/WeakRef.h
    M Source/WTF/wtf/glib/GRefPtr.h
    M Source/WTF/wtf/text/AtomStringImpl.cpp
    M Source/WTF/wtf/text/StringHash.h
    M Source/WTF/wtf/text/SymbolRegistry.cpp
    M Source/WebCore/dom/GCReachableRef.h
    M Source/WebCore/page/SecurityOriginHash.h
    M Source/WebCore/platform/win/COMPtr.h
    M Source/WebCore/rendering/FloatingObjects.h
    M Source/WebCore/rendering/GlyphDisplayListCache.h
    M Source/WebKit/UIProcess/API/cpp/WKRetainPtr.h
    M Tools/TestWebKitAPI/Tests/WTF/WeakPtr.cpp

  Log Message:
  -----------
  Optimize looking up keys by raw reference in hash containers whose key is a non-nullable smart pointer type
https://bugs.webkit.org/show_bug.cgi?id=266166

Reviewed by Darin Adler.

Optimize looking up keys by raw reference in hash containers whose key is a
non-nullable smart pointer type (such as Ref<> / WeakRef<> / CheckedRef<>).

I noticed while adopting WeakRef<> more in our containers that hash container
functions can be passed a raw C++ reference. This is convenient but actually
generates unnecessary refcounting churn for many of these functions because
it creates a WeakRef. Creating a WeakRef is unnecessary for lookup functions
such as contains() / find() and removal functions such as remove() / take().

We already had overloads in place for these functions when passing in
a raw C++ pointer and the key is a smart pointer type to avoid refcounting
churn. However, we didn't have such optimization when passing a raw C++
reference, which is useful when the key type is a non-nullable smart pointer.

This patch adds to our hash containers function overloads that take in a
raw C++ reference, similar to the ones that take in a raw C++ pointer. These
overloads are only available when the key is a non-nullable smart pointer
type.

I also make an improvement to our existing overloads taking in a raw C++
pointer so that they no longer require a non-const pointer. There is no
reason to require a non-const pointer just for pointer hashing and pointer
comparison. I also noticed this issue when adopting more smart pointers in
containers.

* Source/JavaScriptCore/runtime/Identifier.h:
(JSC::IdentifierRepHash::hash):
* Source/WTF/wtf/CheckedPtr.h:
* Source/WTF/wtf/CheckedRef.h:
* Source/WTF/wtf/CompactPtr.h:
* Source/WTF/wtf/ConcurrentPtrHashSet.h:
* Source/WTF/wtf/GetPtr.h:
* Source/WTF/wtf/HashCountedSet.h:
(WTF::Traits>::find):
(WTF::Traits>::find const):
(WTF::Traits>::contains const):
(WTF::Traits>::count const):
(WTF::Traits>::remove):
* Source/WTF/wtf/HashFunctions.h:
* Source/WTF/wtf/HashMap.h:
(WTF::Y>::find):
(WTF::Y>::find const):
(WTF::Y>::contains const):
(WTF::Y>::inlineGet const):
(WTF::Y>::get const):
(WTF::Y>::remove):
(WTF::Y>::take):
* Source/WTF/wtf/HashSet.h:
(WTF::TableTraits>::find const):
(WTF::TableTraits>::contains const):
(WTF::TableTraits>::remove):
(WTF::TableTraits>::take):
* Source/WTF/wtf/ListHashSet.h:
(WTF::U>::find):
(WTF::U>::find const):
(WTF::U>::contains const):
(WTF::U>::insertBefore):
(WTF::U>::remove):
* Source/WTF/wtf/Packed.h:
* Source/WTF/wtf/Ref.h:
* Source/WTF/wtf/RefPtr.h:
* Source/WTF/wtf/RetainPtr.h:
* Source/WTF/wtf/SchedulePair.h:
(WTF::SchedulePairHash::hash):
(WTF::SchedulePairHash::equal):
* Source/WTF/wtf/SignedPtr.h:
* Source/WTF/wtf/UniqueRef.h:
* Source/WTF/wtf/WeakPtr.h:
(WTF::WeakPtr::WeakPtr):
* Source/WTF/wtf/WeakRef.h:
(WTF::WeakRef::releaseImpl):
(WTF::WeakRefHashTraits::take):
* Source/WTF/wtf/glib/GRefPtr.h:
* Source/WTF/wtf/text/StringHash.h:
(WTF::StringHash::hash):
(WTF::ASCIICaseInsensitiveHash::hash):
* Source/WebCore/dom/GCReachableRef.h:
* Source/WebCore/page/SecurityOriginHash.h:
(WebCore::SecurityOriginHash::hash):
(WebCore::SecurityOriginHash::equal):
* Source/WebCore/platform/win/COMPtr.h:
* Source/WebCore/rendering/FloatingObjects.h:
(WebCore::FloatingObjectHashFunctions::hash):
(WebCore::FloatingObjectHashFunctions::equal):
* Source/WebCore/rendering/GlyphDisplayListCache.h:
(WebCore::GlyphDisplayListCacheEntryHash::hash):
(WebCore::GlyphDisplayListCacheEntryHash::equal):
* Source/WebKit/UIProcess/API/cpp/WKRetainPtr.h:
* Tools/TestWebKitAPI/Tests/WTF/WeakPtr.cpp:
(TestWebKitAPI::TestType::resetDidUpdateImplRefCount):
(TestWebKitAPI::TestType::didUpdateImplRefCount const):
(TestWebKitAPI::TEST):

Canonical link: https://commits.webkit.org/271853@main




More information about the webkit-changes mailing list