Bug 208468

Summary: Clear CGColor cache on memory pressure
Product: WebKit Reporter: Chris Dumez <cdumez>
Component: WebCore Misc.Assignee: Chris Dumez <cdumez>
Status: ASSIGNED ---    
Severity: Normal CC: benjamin, cmarcelo, darin, ews-watchlist, sabouhallawa, simon.fraser, ysuzuki
Priority: P2    
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch none

Description Chris Dumez 2020-03-02 13:39:10 PST
Clear CGColor cache on memory pressure.
Comment 1 Chris Dumez 2020-03-02 13:40:43 PST
Created attachment 392182 [details]
Patch
Comment 2 Simon Fraser (smfr) 2020-03-02 13:45:48 PST
How much of it do we just fill up again when we paint?

I think this blanket "clear cache on memory pressure" will often just dirty more pages than we save.
Comment 3 Chris Dumez 2020-03-02 15:59:22 PST
Comment on attachment 392182 [details]
Patch

Will gather some data as this appears to be controversial.
Comment 4 Darin Adler 2020-03-23 16:11:39 PDT
Comment on attachment 392182 [details]
Patch

There’s an NSColor one just like this. Should we be clearing it too?
Comment 5 Darin Adler 2020-03-23 16:12:02 PDT
If we decide to clear either.
Comment 6 Simon Fraser (smfr) 2020-03-23 16:22:08 PDT
I just found SubimageCacheWithTimer, which isn't cleared at all on a memory warning (bug 207957).

I still think our cache management needs to be more centralized.
Comment 7 Darin Adler 2020-03-23 16:22:52 PDT
(In reply to Simon Fraser (smfr) from comment #6)
> I still think our cache management needs to be more centralized.

Sounds good! But what does it mean?
Comment 8 Simon Fraser (smfr) 2020-03-23 16:31:04 PDT
Off the cuff:
* every cache derives from a common base class, registers itself with a cache controller. This would make it harder for people to forget to handle new caches on memory pressure.
* cache controller decides how to reduce in size or clear caches based on memory pressure. Maybe caches have some knobs that describe their time/memory trade-offs

More general goals:
* if clearing caches involves mapping in more memory pages than would be saved, then don't do it (probably requires empirical measurement)
* rewrite caches to make it easier to dump memory pages without touching them