Branch: refs/heads/main Home: https://github.com/WebKit/WebKit Commit: 0ea98bdecabcba02abd3154aef5a17d11f35d9ca https://github.com/WebKit/WebKit/commit/0ea98bdecabcba02abd3154aef5a17d11f35d9ca Author: Chris Dumez <cdu...@apple.com> Date: 2023-12-07 (Thu, 07 Dec 2023)
Changed paths: M Source/WTF/wtf/WeakHashMap.h M Source/WTF/wtf/WeakHashSet.h M Source/WTF/wtf/WeakListHashSet.h M Source/WTF/wtf/WeakPtr.h M Source/WTF/wtf/WeakRef.h M Source/WebCore/dom/EventTarget.cpp M Source/WebCore/dom/EventTarget.h Log Message: ----------- Optimize the creation of WeakPtrs for many object types https://bugs.webkit.org/show_bug.cgi?id=265981 Reviewed by Darin Adler. The performance of WeakPtrs is increasingly important as we adopt it more and more in our code base. As I am working to use WeakPtr more in rendering code, I noticed that the construction of WeakPtr was impact by the fact that WeakPtrFactory was using a data member of type `CompactRefPtrTuple<WeakPtrImpl, uint16_t>` to store a packed WeakPtrImpl pointer in order to free up space for a bitfield. This means that every time we want to construct a WeakPtr from an object, the WeakPtrFactory has to extract the WeakPtrImpl pointer from the CompactRefPtrTuple, which can be costly, especially in Intel hardware. The only type actually leveraging the WeakPtrFactory's bit field is EventTarget. All the other classes (like RenderObject) are just paying this cost without actually getting any benefit from the pointer packing. To address the issue, I renamed WeakPtrFactory to WeakPtrFactoryWithBitField and had EventTarget use this one instead. I introduced a simpler WeakPtrFactory which is using a straight `RefPtr<WeakPtrImpl>` instead, which every other type is now using. Based on my A/B testing, this should allow us to replace CheckedPtr / CheckedRef with WeakPtr / WeakRef in rendering code without regressing our benchmarks. * Source/WTF/wtf/WeakHashMap.h: * Source/WTF/wtf/WeakHashSet.h: * Source/WTF/wtf/WeakListHashSet.h: * Source/WTF/wtf/WeakPtr.h: (WTF::WeakPtr::implForObject): (WTF::WeakPtrFactory::~WeakPtrFactory): (WTF::WeakPtrFactory::impl const): (WTF::WeakPtrFactory::initializeIfNeeded const): (WTF::WeakPtrFactory::createWeakPtr const): (WTF::WeakPtrFactory::revokeAll): (WTF::WeakPtrFactory::weakPtrCount const): (WTF::WeakPtrFactory::isInitialized const): (WTF::WeakPtrFactoryWithBitField::WeakPtrFactoryWithBitField): (WTF::WeakPtrFactoryWithBitField::~WeakPtrFactoryWithBitField): (WTF::WeakPtrFactoryWithBitField::impl const): (WTF::CanMakeWeakPtrBase::weakPtrFactory const): (WTF::CanMakeWeakPtrBase::weakPtrFactory): (WTF::CanMakeWeakPtrBase::CanMakeWeakPtrBase): (WTF::CanMakeWeakPtrBase::operator=): (WTF::CanMakeWeakPtrBase::initializeWeakPtrFactory): (WTF::WeakPtrFactory::impl): Deleted. (WTF::WeakPtrFactory::bitfield const): Deleted. (WTF::WeakPtrFactory::setBitfield const): Deleted. (WTF::CanMakeWeakPtr::weakPtrFactory const): Deleted. (WTF::CanMakeWeakPtr::weakPtrFactory): Deleted. (WTF::CanMakeWeakPtr::CanMakeWeakPtr): Deleted. (WTF::CanMakeWeakPtr::operator=): Deleted. (WTF::CanMakeWeakPtr::initializeWeakPtrFactory): Deleted. * Source/WTF/wtf/WeakRef.h: (WTF::WeakRef::implForObject): * Source/WebCore/dom/EventTarget.h: Canonical link: https://commits.webkit.org/271701@main _______________________________________________ webkit-changes mailing list webkit-changes@lists.webkit.org https://lists.webkit.org/mailman/listinfo/webkit-changes