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

Issue 2205843003: Use weak members to cache StyleSheetContents. (Closed)

Created:
4 years, 4 months ago by rune
Modified:
4 years, 4 months ago
Reviewers:
haraken, Timothy Loh
CC:
chromium-reviews, blink-reviews-html_chromium.org, blink-reviews-style_chromium.org, blink-reviews-css, sof, eae+blinkwatch, blink-reviews-dom_chromium.org, dglazkov+blink, apavlov+blink_chromium.org, darktears, blink-reviews, rwlbuis
Base URL:
https://chromium.googlesource.com/chromium/src.git@master
Target Ref:
refs/pending/heads/master
Project:
chromium
Visibility:
Public.

Description

Use weak members to cache StyleSheetContents. We used the client count to detect if we could remove a StyleSheetContents from the StyleEngine cache or not. The problem is that the client references are removed when the element is removed from the DOM, but the StyleSheetContents is still referenced from the CSSStyleSheet which is accessible from CSSOM. That caused bugs with StyleSheetContents being marked as mutable without removing it from the cache causing assertions, and mutating the sheet without copy-on-write because we thought we only had a single client for the contents. Instead use weak members in the cache and let garbage collection delete the StyleSheetContents when no longer referenced. Also, add a flag to StyleSheetContents to say that it is referenced by multiple sheets when we use and already cached object instead of incorrectly relying on client count. R=timloh@chromium.org,haraken@chromium.org BUG=633210, 628488 Committed: https://crrev.com/473ac0866d46d55bf57293ce3bb27870f672dc40 Cr-Commit-Position: refs/heads/master@{#409495}

Patch Set 1 #

Patch Set 2 : Another CORE_EXPORT #

Patch Set 3 : Might be in cache without being used before garbage collection #

Total comments: 2
Unified diffs Side-by-side diffs Delta from patch set Stats (+87 lines, -36 lines) Patch
A third_party/WebKit/LayoutTests/fast/css/modify-cached-detached-sheet.html View 1 chunk +13 lines, -0 lines 0 comments Download
A third_party/WebKit/LayoutTests/fast/css/modify-cached-detached-sheet-2.html View 1 chunk +21 lines, -0 lines 0 comments Download
M third_party/WebKit/Source/core/css/CSSStyleSheet.cpp View 1 chunk +1 line, -3 lines 0 comments Download
M third_party/WebKit/Source/core/css/StyleSheetContents.h View 1 2 3 chunks +4 lines, -1 line 0 comments Download
M third_party/WebKit/Source/core/css/StyleSheetContents.cpp View 5 chunks +2 lines, -12 lines 2 comments Download
M third_party/WebKit/Source/core/dom/StyleElement.h View 1 1 chunk +1 line, -1 line 0 comments Download
M third_party/WebKit/Source/core/dom/StyleEngine.h View 2 chunks +2 lines, -3 lines 0 comments Download
M third_party/WebKit/Source/core/dom/StyleEngine.cpp View 1 2 2 chunks +7 lines, -15 lines 0 comments Download
M third_party/WebKit/Source/core/dom/StyleEngineTest.cpp View 2 chunks +35 lines, -0 lines 0 comments Download
M third_party/WebKit/Source/core/html/HTMLStyleElement.h View 1 chunk +1 line, -1 line 0 comments Download

Messages

Total messages: 31 (20 generated)
rune
ptal @haraken, please take a look at the WeakMember usage in the StyleEngine caches and ...
4 years, 4 months ago (2016-08-02 21:20:33 UTC) #13
haraken
The WeakMember usage looks good, but isn't there any case where you need to explicitly ...
4 years, 4 months ago (2016-08-03 01:01:18 UTC) #14
rune
https://codereview.chromium.org/2205843003/diff/40001/third_party/WebKit/Source/core/css/StyleSheetContents.cpp File third_party/WebKit/Source/core/css/StyleSheetContents.cpp (left): https://codereview.chromium.org/2205843003/diff/40001/third_party/WebKit/Source/core/css/StyleSheetContents.cpp#oldcode103 third_party/WebKit/Source/core/css/StyleSheetContents.cpp:103: removeSheetFromCache(document); On 2016/08/03 01:01:18, haraken wrote: > > For ...
4 years, 4 months ago (2016-08-03 09:20:05 UTC) #15
haraken
On 2016/08/03 09:20:05, rune wrote: > https://codereview.chromium.org/2205843003/diff/40001/third_party/WebKit/Source/core/css/StyleSheetContents.cpp > File third_party/WebKit/Source/core/css/StyleSheetContents.cpp (left): > > https://codereview.chromium.org/2205843003/diff/40001/third_party/WebKit/Source/core/css/StyleSheetContents.cpp#oldcode103 > ...
4 years, 4 months ago (2016-08-03 09:25:01 UTC) #16
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.org/2205843003/40001
4 years, 4 months ago (2016-08-03 09:38:57 UTC) #20
commit-bot: I haz the power
Internal error: failed to checkout. Please try again.
4 years, 4 months ago (2016-08-03 09:45:42 UTC) #22
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.org/2205843003/40001
4 years, 4 months ago (2016-08-03 12:14:37 UTC) #26
commit-bot: I haz the power
Committed patchset #3 (id:40001)
4 years, 4 months ago (2016-08-03 12:18:18 UTC) #27
commit-bot: I haz the power
Patchset 3 (id:??) landed as https://crrev.com/473ac0866d46d55bf57293ce3bb27870f672dc40 Cr-Commit-Position: refs/heads/master@{#409495}
4 years, 4 months ago (2016-08-03 12:19:51 UTC) #29
kouhei (in TOK)
On 2016/08/03 12:19:51, commit-bot: I haz the power wrote: > Patchset 3 (id:??) landed as ...
4 years, 4 months ago (2016-08-07 12:15:26 UTC) #30
rune
4 years, 4 months ago (2016-08-07 17:28:35 UTC) #31
Message was sent while issue was closed.
On 2016/08/07 12:15:26, kouhei wrote:
> On 2016/08/03 12:19:51, commit-bot: I haz the power wrote:
> > Patchset 3 (id:??) landed as
> > https://crrev.com/473ac0866d46d55bf57293ce3bb27870f672dc40
> > Cr-Commit-Position: refs/heads/master@{#409495}
> 
> This CL hugely improved the StyleSheetInsert* perf benchmarks. Congrats!
>
https://chromeperf.appspot.com/group_report?keys=agxzfmNocm9tZXBlcmZyFAsSB0Fu...

That's not intentional, but looking at the test I know why it happens. It's the
same stylesheet text being repeatedly inserted and removed. Before my change,
the cache entry would be removed immediately when removed and the stylesheet
would have to be reparsed every time. With this CL, the weak reference is not
collected until the next time the sheet is created, and it can utilize the
cached entry.

Powered by Google App Engine
This is Rietveld 408576698