Bug 55873

Summary: Use HashMaps for caching primitive values
Product: WebKit Reporter: Antti Koivisto <koivisto>
Component: CSSAssignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Normal CC: abarth, ap, eric, mitz, oliver, webkit.review.bot
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: PC   
OS: OS X 10.5   
Attachments:
Description Flags
use HashMaps instead of fixed size arrays for caching sam: review+

Description Antti Koivisto 2011-03-07 06:00:39 PST
Both the memory efficiency and sharing efficiency of CSSPrimitiveValueCache can be improved by using HashMaps instead of fixed size arrays.
Comment 1 Antti Koivisto 2011-03-07 06:20:59 PST
Created attachment 84939 [details]
use HashMaps instead of fixed size arrays for caching

This removes the fixed per-document cost of empty cache (was ~10kb on 32bit)  while also somewhat improving caching efficiency (~5% from expanded integer range which more than pays for itself). Caches usually cover only a fraction of possible values so increased per-item cost from the hash table is ok.
Comment 2 WebKit Review Bot 2011-03-07 06:24:03 PST
Attachment 84939 [details] did not pass style-queue:

Failed to run "['Tools/Scripts/check-webkit-style', '--diff-files', u'Source/WebCore/ChangeLog', u'Source/WebCor..." exit_code: 1

Source/WebCore/css/CSSPrimitiveValueCache.cpp:97:  Tests for true/false, null/non-null, and zero/non-zero should all be done without equality comparisons.  [readability/comparison_to_zero] [5]
Source/WebCore/css/CSSPrimitiveValueCache.cpp:102:  Tests for true/false, null/non-null, and zero/non-zero should all be done without equality comparisons.  [readability/comparison_to_zero] [5]
Source/WebCore/css/CSSPrimitiveValueCache.cpp:107:  Tests for true/false, null/non-null, and zero/non-zero should all be done without equality comparisons.  [readability/comparison_to_zero] [5]
Total errors found: 3 in 3 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 3 mitz 2011-03-07 08:22:09 PST
Comment on attachment 84939 [details]
use HashMaps instead of fixed size arrays for caching

View in context: https://bugs.webkit.org/attachment.cgi?id=84939&action=review

> Source/WebCore/css/CSSPrimitiveValueCache.cpp:53
> +        m_identifierValueCache.add(ident, primitiveValue);

A get() followed by an add() means two cache lookups. You can do this with a single add().
Comment 4 Sam Weinig 2011-03-07 09:00:35 PST
Comment on attachment 84939 [details]
use HashMaps instead of fixed size arrays for caching

View in context: https://bugs.webkit.org/attachment.cgi?id=84939&action=review

> Source/WebCore/css/CSSPrimitiveValueCache.cpp:119
> +    RefPtr<CSSPrimitiveValue> primitiveValue = cache->get(intValue);
>      if (!primitiveValue) {
>          primitiveValue = CSSPrimitiveValue::create(value, type);
> -        m_integerValueCache[intValue][type] = primitiveValue;
> +        cache->add(intValue, primitiveValue);
>      }

Same comment as the the one mitz gave above. This can be done with one hash lookup.
Comment 5 Antti Koivisto 2011-03-07 10:54:10 PST
http://trac.webkit.org/changeset/80477 (with single hash lookups)
Comment 6 WebKit Review Bot 2011-03-07 11:10:49 PST
http://trac.webkit.org/changeset/80477 might have broken Qt Linux Release