Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: 3be22f2c041ad7c342aeccd4fb5970c940c44a5b
https://github.com/WebKit/WebKit/commit/3be22f2c041ad7c342aeccd4fb5970c940c44a5b
Author: Chris Dumez <[email protected]>
Date: 2026-03-30 (Mon, 30 Mar 2026)
Changed paths:
M Source/WebCore/dom/CollectionIndexCache.h
M Source/WebCore/html/HTMLCollection.h
Log Message:
-----------
Improve HTMLCollection memoryCost() accuracy
https://bugs.webkit.org/show_bug.cgi?id=311043
Reviewed by Ryosuke Niwa.
CollectionNamedElementCache::memoryCost() was significantly underestimating
memory usage by counting each HashMap entry as sizeof(Element*) (8 bytes),
when the actual per-bucket cost includes the key, the Vector<WeakRef<Element>>
value, and HashMap bucket overhead. Use HashMap::byteSize() which returns
the exact allocation size of the hash table. Also use Vector::capacity()
instead of size() for m_propertyNames to account for over-allocation.
The old comment incorrectly claimed HashMap::size() doesn't chase pointers;
it does (via m_table). Thread safety is actually ensured by the cache being
immutable after creation and its lifetime being protected by
m_namedElementCacheAssignmentLock. Updated the comment to reflect this.
Also add missing `const` qualifier to CollectionIndexCache::memoryCost().
* Source/WebCore/dom/CollectionIndexCache.h:
(WebCore::CollectionIndexCache::memoryCost const):
(WebCore::CollectionIndexCache::memoryCost): Deleted.
* Source/WebCore/html/HTMLCollection.h:
(WebCore::CollectionNamedElementCache::memoryCost const):
Canonical link: https://commits.webkit.org/310211@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications