RESOLVED FIXED 86434
RuleSet::addToRuleSet wastes a bit of Vector capacity
https://bugs.webkit.org/show_bug.cgi?id=86434
Summary RuleSet::addToRuleSet wastes a bit of Vector capacity
Simon Fraser (smfr)
Reported 2012-05-14 21:40:53 PDT
Data collected via bug 86281 show that RuleSet::addToRuleSet() is the most wasteful call site for excess vector capacity.
Attachments
Proposed patch (1.30 KB, patch)
2012-05-15 08:52 PDT, Andreas Kling
koivisto: review+
Andreas Kling
Comment 1 2012-05-14 21:44:18 PDT
Hm. This is somewhat surprising since we shrinkToFit() most of the vectors in RuleSet::shrinkToFit(). Something must be going wrong here. :/
Antti Koivisto
Comment 2 2012-05-15 01:30:28 PDT
Simon, does your logging work correctly when shrinkToFit is used?
Simon Fraser (smfr)
Comment 3 2012-05-15 08:14:07 PDT
Apparently not (you can see the patch in bug 86281).
Simon Fraser (smfr)
Comment 4 2012-05-15 08:44:31 PDT
Previous data was not taking shrinkToFit into account. New data shows addToRuleSet() to be a lot less wasteful, but there is one stack that shows up in the top 20: 117 vectors, 7.11KB used of 73.12KB, 66.02KB wasted at: 1 0x108c1a255 WTF::Vector<WebCore::RuleData, 0ul>::Vector() 2 0x108c07a55 WTF::Vector<WebCore::RuleData, 0ul>::Vector() 3 0x108bfb4e1 WebCore::RuleSet::addToRuleSet(WTF::AtomicStringImpl*, WTF::HashMap<WTF::AtomicStringImpl*, WTF::OwnPtr<WTF::Vector<WebCore::RuleData, 0ul> >, WTF::PtrHash<WTF::AtomicStringImpl*>, WTF::HashTraits<WTF::AtomicStringImpl*>, WTF::HashTraits<WTF::OwnPtr<WTF::Vector<WebCore::RuleData, 0ul> > > >&, WebCore::RuleData const&) 4 0x108bfb6fb WebCore::RuleSet::addRule(WebCore::StyleRule*, WebCore::CSSSelector*, bool, bool, bool) 5 0x108beac71 _ZN7WebCoreL11makeRuleSetERKN3WTF6VectorINS_13StyleResolver11RuleFeatureELm0EEE
Andreas Kling
Comment 5 2012-05-15 08:52:28 PDT
Created attachment 141983 [details] Proposed patch
Antti Koivisto
Comment 6 2012-05-15 09:09:01 PDT
Comment on attachment 141983 [details] Proposed patch View in context: https://bugs.webkit.org/attachment.cgi?id=141983&action=review r=me > Source/WebCore/ChangeLog:3 > + RuleSet::addToRuleSet wastes a lot of Vector capacity. You might want to update the title. This hardly wastes "a lot".
Andreas Kling
Comment 7 2012-05-15 09:45:35 PDT
Darin Adler
Comment 8 2012-05-15 09:50:22 PDT
In cases like this where we know the size the RuleSet will be before we create it, it would be more efficient to reserve capacity than to shrink to fit. All we’d have to do is make a RuleSet::create function overload that takes a capacity. What do you guys think of that idea?
Darin Adler
Comment 9 2012-05-15 09:54:45 PDT
Well maybe this is the only call site like that; the point is that you save more memory by not allocating the larger block and shrinking. I suspect that in many cases the memory saved by shrinking after the fact can’t be reused due to fragmentation.
Andreas Kling
Comment 10 2012-05-15 09:58:42 PDT
(In reply to comment #8) > In cases like this where we know the size the RuleSet will be before we create it, it would be more efficient to reserve capacity than to shrink to fit. All we’d have to do is make a RuleSet::create function overload that takes a capacity. > > What do you guys think of that idea? I like the idea in principle. If you look at the implementation of RuleSet::shrinkToFit() however, it's nontrivial to predict at RuleSet::create() time how big each subvector should be.
Darin Adler
Comment 11 2012-05-15 10:03:28 PDT
OK. Got it.
Darin Adler
Comment 12 2012-05-15 10:03:59 PDT
One last thought on this: The prediction can be wrong some of the time as long as it’s right most of the time.
Note You need to log in before you can comment on or make changes to this bug.