Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(669)

Issue 16161005: Reduce CSSProperty's StylePropertyMetadata memory footprint by half when used inside a ImmutableSty… (Closed)

Created:
7 years, 6 months ago by darktears
Modified:
7 years, 6 months ago
CC:
blink-reviews, apavlov+blink_chromium.org, dglazkov+blink, eae+blinkwatch, esprehn
Visibility:
Public.

Description

Reduce CSSProperty's StylePropertyMetadata memory footprint by half when used inside a ImmutableStylePropertySet. Today CSSProperty holds its metadata in the following way : - m_propertyID: 14 bits to hold the propertyID it represents. We use 14 bits because CSSPropertyIDs start at 1001. - m_shorthandID: These bits are used only to store if this given property was set part of a shorthand. For example if border-top-color was set from border-color or border. It will be 0 if just the longhand alone was set. Again 14 bits to hold the CSSPropertyID of this shorthand. - m_important: 1 bit used to describe if the property is !important or not. - m_implicit: 1 bit used to describe if the property was implicitly set or not. For example border-color: red will set border-color-top/right/left/bottom implicitly. - m_inherited: 1 bit used to describe if the property value was inherited or not. The proposal to decrease the memory footprint on CSSProperty's metadata only stand when stored inside ImmutableStylePropertySet which uses a custom way to allocate and lay out the StylePropertyMetadata and the CSSValues in memory because the idea behind is that the content will not change. The MutableStylePropertySet uses a regular vector to retrieve, remove and modify the CSSProperties. ImmutableStylePropertySet is used by default when parsing up until someone start to access the CSSOM like div.style which will convert the immutable to a mutable set. It is also good to note that a CSSProperty is created for every single statement inside a block in a stylesheet so we do have quite a bunch around. Another consideration is that the only client to the m_shorthandID is the inspector which uses it to group the longhands into a shorthand drop down list. The new proposal is the following one : - Reduce m_propertyID to 10 bits by not starting the CSSPropertyIDs from 1001 but rather 0 (or 3 as two are hardcoded CSSPropertyInvalid and CSSPropertyVariable). After previous refactor in https://src.chromium.org/viewvc/blink?revision=151975&view=revision and https://src.chromium.org/viewvc/blink?view=revision&revision=151920 it is safe to make this change. - Use the fact that we statically know which longhand belong to which shorthand. So we create a static mapping between longhands and shorthands. Here is the new layout : - m_propertyID : 10 bits. We have up until 1024 properties. We have today 399, it will take many years to reach 1024. A little message will make sure that when 1024 is reached people will have to modify CSSProperty. - m_isSetFromShorthand : 1 bit to set wether this property was set from a shorthand or not. This is all we need to know. From the propertyID we can retrieve which shorthand it was set from using the new code in StylePropertyShorthand. - m_indexInShorthandsVector : 2 bits, unfortunately there are few longhands which belong to multiple shorthands so we need to store which was this longhand was part at parsing time. Notice that it does not store the CSSPropertyID of the matching shorthand but rather its position in the vector of matching shorthands. CSSProperty::m_shorthandID() method make it transparent for call sites and return the actual CSSPropertyID of the shorthand. So far 2 bits seems enough as there is only few longhands with ambiguity and they belong to 3 shorthands. StylePropertyShorthand diff adds lot of boilerplate code, it may sounds scarry but it's temporary. In a following CL we'll make sure that this entire file is generated from a .in just like StyleBuilder or others. That .in will just store the description of a shorthand and its longhand and we will generate the entire file. We now have all the requirements so we can generate all of it. Please note also that this patch does not modify yet ImmutableStylePropertySet to take into account the new size of the metadatas. Again this will come in a following CL to keep this change focused. Committed: https://src.chromium.org/viewvc/blink?view=rev&revision=152481

Patch Set 1 #

Patch Set 2 : #

Total comments: 2

Patch Set 3 : #

Total comments: 2

Patch Set 4 : #

Total comments: 2

Patch Set 5 : #

Unified diffs Side-by-side diffs Delta from patch set Stats (+492 lines, -74 lines) Patch
M Source/core/css/CSSComputedStyleDeclaration.cpp View 1 2 3 1 chunk +2 lines, -2 lines 0 comments Download
M Source/core/css/CSSParser.cpp View 1 2 3 1 chunk +22 lines, -2 lines 0 comments Download
M Source/core/css/CSSProperty.h View 1 2 3 4 2 chunks +18 lines, -16 lines 0 comments Download
M Source/core/css/CSSProperty.cpp View 1 2 3 4 2 chunks +11 lines, -1 line 0 comments Download
M Source/core/css/StylePropertySet.h View 1 chunk +1 line, -1 line 0 comments Download
M Source/core/css/StylePropertySet.cpp View 1 2 3 4 1 chunk +13 lines, -3 lines 0 comments Download
M Source/core/css/StylePropertyShorthand.h View 4 chunks +14 lines, -3 lines 0 comments Download
M Source/core/css/StylePropertyShorthand.cpp View 1 2 28 chunks +407 lines, -45 lines 0 comments Download
M Source/core/scripts/make_css_property_names.py View 1 chunk +4 lines, -1 line 0 comments Download

Messages

Total messages: 12 (0 generated)
darktears
Please do not look the try bots the tree is busted for now. https://gist.github.com/anonymous/5733266 for ...
7 years, 6 months ago (2013-06-08 00:12:57 UTC) #1
eseidel
Very cool.
7 years, 6 months ago (2013-06-08 02:33:03 UTC) #2
eseidel
Moving metadata from 32bits to 16-bits will only help if compilers pack mismatched types on ...
7 years, 6 months ago (2013-06-08 22:00:48 UTC) #3
darktears
On 2013/06/08 22:00:48, eseidel wrote: > Moving metadata from 32bits to 16-bits will only help ...
7 years, 6 months ago (2013-06-10 11:07:37 UTC) #4
apavlov
On 2013/06/10 11:07:37, darktears wrote: > On 2013/06/08 22:00:48, eseidel wrote: > > Moving metadata ...
7 years, 6 months ago (2013-06-10 15:13:44 UTC) #5
Julien - ping for review
I am not super enthusiastic about #pragma as it is compiler specific. The fact that ...
7 years, 6 months ago (2013-06-10 23:29:57 UTC) #6
darktears
On 2013/06/10 23:29:57, Julien Chaffraix wrote: > I am not super enthusiastic about #pragma as ...
7 years, 6 months ago (2013-06-10 23:40:09 UTC) #7
Julien - ping for review
https://codereview.chromium.org/16161005/diff/26001/Source/core/css/CSSProperty.cpp File Source/core/css/CSSProperty.cpp (right): https://codereview.chromium.org/16161005/diff/26001/Source/core/css/CSSProperty.cpp#newcode47 Source/core/css/CSSProperty.cpp:47: if (shorthands.size() > 1) { Do we really need ...
7 years, 6 months ago (2013-06-14 17:38:27 UTC) #8
darktears
On 2013/06/14 17:38:27, Julien Chaffraix wrote: > https://codereview.chromium.org/16161005/diff/26001/Source/core/css/CSSProperty.cpp > File Source/core/css/CSSProperty.cpp (right): > > https://codereview.chromium.org/16161005/diff/26001/Source/core/css/CSSProperty.cpp#newcode47 ...
7 years, 6 months ago (2013-06-14 19:49:25 UTC) #9
Julien - ping for review
lgtm https://codereview.chromium.org/16161005/diff/38001/Source/core/css/CSSProperty.cpp File Source/core/css/CSSProperty.cpp (right): https://codereview.chromium.org/16161005/diff/38001/Source/core/css/CSSProperty.cpp#newcode40 Source/core/css/CSSProperty.cpp:40: CSSPropertyID StylePropertyMetadata::shorthandID() const We may want to rename ...
7 years, 6 months ago (2013-06-14 20:09:06 UTC) #10
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/alexis.menard@intel.com/16161005/49001
7 years, 6 months ago (2013-06-14 20:25:49 UTC) #11
commit-bot: I haz the power
7 years, 6 months ago (2013-06-14 22:42:03 UTC) #12
Message was sent while issue was closed.
Change committed as 152481

Powered by Google App Engine
This is Rietveld 408576698