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

Issue 17314010: RuleSet causes 600 kB of memory fragmentation (Closed)

Created:
7 years, 6 months ago by abarth-chromium
Modified:
7 years, 6 months ago
Reviewers:
esprehn, ojan
CC:
blink-reviews, loislo+blink_chromium.org, eae+blinkwatch, yurys+blink_chromium.org, dglazkov+blink, apavlov+blink_chromium.org, adamk+blink_chromium.org, darktears, jeez
Visibility:
Public.

Description

RuleSet causes 600 kB of memory fragmentation RuleSet stores data as a HashMap from AtomicStringImpls to Vector<RuleData>. When each CSS rule has a different class selector, each Vector is populated with a single value. When you add the first value to a Vector, the Vector pre-allocates 16 slots, which means there's 15 * sizeof(RuleData) wasted space. We're smart and shrink these Vectors down to size, but that shrinkage doesn't actually results in freeing up memory because of heap fragmentation. This CL changes how we constructo RuleSet objects. During construction, we use a LinkedStack, which lets us build each HashMap entry incrementally without needing to preallocate a large number of moderately sized chunks. After we're done building the RuleSet, we compact the representation back into Vectors. At that time, we know exactly how large each Vector needs to be and we can size them precisely to meet our needs. This CL has two effects on memory usage: 1) Lower peek memory usage. When building the RuleSet, we no longer pre-allocate megabytes of Vector buffers. 2) Lower heap fragmentation. When compacting the RuleSet, we no longer leave thousands of holes in the heap. I measured the impact of this change using CSS extracted from Mobile Gmail. On the Mobile Gmail CSS, the VmRSS of the content_shell render process is 200 kB smaller after this CL (measured on Linux). Additionally, I wrote some synthetic CSS that contained 2000 empty CSS rules with unique class name selectors. On that case, the VmRSS of the content_shell render process after loading the page shrinks by 676 kB. I also measured that the peek memory usage improvement was of a similar scale, but I unfortunately don't have the data anymore. R=ojan Committed: https://src.chromium.org/viewvc/blink?view=rev&revision=152839

Patch Set 1 #

Total comments: 15

Patch Set 2 : fix boog #

Patch Set 3 : Address reviewer feedback #

Unified diffs Side-by-side diffs Delta from patch set Stats (+142 lines, -77 lines) Patch
M Source/core/css/RuleSet.h View 1 2 4 chunks +40 lines, -25 lines 0 comments Download
M Source/core/css/RuleSet.cpp View 1 2 5 chunks +39 lines, -21 lines 0 comments Download
A + Source/wtf/LinkedStack.h View 1 2 1 chunk +62 lines, -31 lines 0 comments Download
M Source/wtf/wtf.gypi View 1 chunk +1 line, -0 lines 0 comments Download

Messages

Total messages: 16 (0 generated)
abarth-chromium
7 years, 6 months ago (2013-06-20 22:08:40 UTC) #1
abarth-chromium
7 years, 6 months ago (2013-06-20 22:09:24 UTC) #2
esprehn
Awesome! Couple comments... https://codereview.chromium.org/17314010/diff/1/Source/core/css/RuleSet.cpp File Source/core/css/RuleSet.cpp (right): https://codereview.chromium.org/17314010/diff/1/Source/core/css/RuleSet.cpp#newcode389 Source/core/css/RuleSet.cpp:389: void RuleSet::compactPendingRules(PendingRuleMap& pendingMap, CompactRuleMap& compactMap) nit: ...
7 years, 6 months ago (2013-06-20 22:29:52 UTC) #3
ojan
https://codereview.chromium.org/17314010/diff/1/Source/core/css/RuleSet.cpp File Source/core/css/RuleSet.cpp (right): https://codereview.chromium.org/17314010/diff/1/Source/core/css/RuleSet.cpp#newcode213 Source/core/css/RuleSet.cpp:213: bool RuleSet::findBestRuleSetAndAdd(const CSSSelector* component, RuleData& ruleData) Should we ASSERT(m_pendingRules) ...
7 years, 6 months ago (2013-06-20 22:38:45 UTC) #4
ojan
lgtm
7 years, 6 months ago (2013-06-20 22:39:03 UTC) #5
ojan
On 2013/06/20 22:39:03, ojan wrote: > lgtm not lgtm whoops, didn't see elliots comments.
7 years, 6 months ago (2013-06-20 22:39:36 UTC) #6
abarth-chromium
https://codereview.chromium.org/17314010/diff/1/Source/core/css/RuleSet.cpp File Source/core/css/RuleSet.cpp (right): https://codereview.chromium.org/17314010/diff/1/Source/core/css/RuleSet.cpp#newcode213 Source/core/css/RuleSet.cpp:213: bool RuleSet::findBestRuleSetAndAdd(const CSSSelector* component, RuleData& ruleData) On 2013/06/20 22:38:45, ...
7 years, 6 months ago (2013-06-20 22:52:31 UTC) #7
esprehn
On 2013/06/20 22:52:31, abarth wrote: > ... > > The PendingRuleMap and CompactRuleMap types are ...
7 years, 6 months ago (2013-06-20 22:57:14 UTC) #8
abarth-chromium
On 2013/06/20 22:57:14, esprehn wrote: > On 2013/06/20 22:52:31, abarth wrote: > > The function ...
7 years, 6 months ago (2013-06-20 23:00:23 UTC) #9
adamk
On 2013/06/20 23:00:23, abarth wrote: > On 2013/06/20 22:57:14, esprehn wrote: > > On 2013/06/20 ...
7 years, 6 months ago (2013-06-20 23:05:29 UTC) #10
abarth-chromium
On 2013/06/20 23:05:29, adamk wrote: > Sorry for the drive-by, but why move it to ...
7 years, 6 months ago (2013-06-20 23:10:48 UTC) #11
adamk
On 2013/06/20 23:05:29, adamk wrote: > On 2013/06/20 23:00:23, abarth wrote: > > On 2013/06/20 ...
7 years, 6 months ago (2013-06-20 23:11:40 UTC) #12
abarth-chromium
PTAL
7 years, 6 months ago (2013-06-20 23:12:43 UTC) #13
ojan
lgtm
7 years, 6 months ago (2013-06-20 23:29:25 UTC) #14
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/abarth@chromium.org/17314010/18001
7 years, 6 months ago (2013-06-20 23:31:42 UTC) #15
commit-bot: I haz the power
7 years, 6 months ago (2013-06-21 01:03:28 UTC) #16
Message was sent while issue was closed.
Change committed as 152839

Powered by Google App Engine
This is Rietveld 408576698