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

Issue 1857543002: Don't recreate SkImages for high-res (GIF, WEBP...) animations. (Closed)

Created:
4 years, 8 months ago by aleksandar.stojiljkovic
Modified:
4 years, 7 months ago
CC:
chromium-reviews, krit, pdr+graphicswatchlist_chromium.org, drott+blinkwatch_chromium.org, blink-reviews-platform-graphics_chromium.org, dshwang, jbroman, Justin Novosad, Rik, Stephen Chennney, blink-reviews, f(malita), danakj+watch_chromium.org, kinuko+watch, rwlbuis, reed1, noel
Base URL:
https://chromium.googlesource.com/chromium/src.git@master
Target Ref:
refs/pending/heads/master
Project:
chromium
Visibility:
Public.

Description

Don't recreate SkImages for high-res (GIF) animations. Since original patch [1], pixel data caching got moved to skia discardable memory and recently to SoftwareImageDecodeController. As ImageDecoder already caches only one (2 in some cases) frame, this code's effect was to remove SkImage for animations where all combined frames data is over 5 MB. [1] original patch, @pkasting, Dec 2008 https://chromium.googlesource.com/chromium/src/+/f868b0862a903e2a4ffa0fc975080a09ad73cb64 The problem caused here (re-decoding and increased memory allocation) is that SkImage::uniqueID() is used as SoftwareImageDecodeController::decoded_images_ cache key - clearing it causes that cache is filled for every loop and every frame rendered (always decoding and adding to cache). Next loop's SkImages have different uniqueId and keep filling up the cache with duplicates of same frames, evicting useful content. Detailed information about the issue is in comment here [2] [2] https://bugs.chromium.org/p/chromium/issues/detail?id=165750#c13 BUG=165750

Patch Set 1 #

Patch Set 2 : review #4 fix. Thanks @pkasting. #

Total comments: 1
Unified diffs Side-by-side diffs Delta from patch set Stats (+19 lines, -69 lines) Patch
M third_party/WebKit/Source/core/fetch/ImageResource.cpp View 1 1 chunk +1 line, -1 line 0 comments Download
M third_party/WebKit/Source/core/layout/ImageQualityControllerTest.cpp View 1 3 chunks +3 lines, -3 lines 0 comments Download
M third_party/WebKit/Source/core/svg/graphics/SVGImage.h View 1 1 chunk +1 line, -1 line 0 comments Download
M third_party/WebKit/Source/core/svg/graphics/SVGImageForContainer.h View 1 1 chunk +1 line, -1 line 0 comments Download
M third_party/WebKit/Source/platform/DragImageTest.cpp View 1 1 chunk +1 line, -1 line 0 comments Download
M third_party/WebKit/Source/platform/graphics/BitmapImage.h View 1 1 chunk +4 lines, -11 lines 0 comments Download
M third_party/WebKit/Source/platform/graphics/BitmapImage.cpp View 1 4 chunks +2 lines, -20 lines 0 comments Download
M third_party/WebKit/Source/platform/graphics/BitmapImageTest.cpp View 1 4 chunks +2 lines, -27 lines 1 comment Download
M third_party/WebKit/Source/platform/graphics/GeneratedImage.h View 1 1 chunk +1 line, -1 line 0 comments Download
M third_party/WebKit/Source/platform/graphics/Image.h View 1 1 chunk +1 line, -1 line 0 comments Download
M third_party/WebKit/Source/platform/graphics/ImageLayerChromiumTest.cpp View 1 1 chunk +1 line, -1 line 0 comments Download
M third_party/WebKit/Source/platform/graphics/StaticBitmapImage.h View 1 1 chunk +1 line, -1 line 0 comments Download

Messages

Total messages: 14 (4 generated)
aleksandar.stojiljkovic
Review needed from @senorblanco, as the owner. Cc-ing @pkasting, as author of original patch, @vmpstr, ...
4 years, 8 months ago (2016-04-02 14:32:34 UTC) #3
Peter Kasting
It seems like this eliminates any need for destroyDecodedData(). I don't think that's used outside ...
4 years, 8 months ago (2016-04-03 09:14:52 UTC) #4
Peter Kasting
Also, from your description, it sounds as if this is a workaround for some suboptimal ...
4 years, 8 months ago (2016-04-03 09:18:45 UTC) #5
aleksandar.stojiljkovic
On 2016/04/03 09:14:52, Peter Kasting wrote: > It seems like this eliminates any need for ...
4 years, 8 months ago (2016-04-03 10:35:02 UTC) #6
aleksandar.stojiljkovic
On 2016/04/03 09:18:45, Peter Kasting wrote: > Also, from your description, it sounds as if ...
4 years, 8 months ago (2016-04-03 11:17:15 UTC) #7
aleksandar.stojiljkovic
Patch Set 2 : review #4 fix. Thanks @pkasting.
4 years, 8 months ago (2016-04-03 12:55:01 UTC) #8
f(malita)
I think this change makes sense, but do you mind checking the impact on memory? ...
4 years, 8 months ago (2016-04-04 15:33:16 UTC) #10
Peter Kasting
LGTM on the code itself. fmalita's concerns about overall behavior are stuff I'm not as ...
4 years, 8 months ago (2016-04-05 01:55:58 UTC) #12
aleksandar.stojiljkovic
On 2016/04/04 15:33:16, f(malita) wrote: > I think this change makes sense, but do you ...
4 years, 8 months ago (2016-04-05 17:27:17 UTC) #13
aleksandar.stojiljkovic
4 years, 7 months ago (2016-04-27 15:49:33 UTC) #14
On 2016/04/05 17:27:17, aleksandar.stojiljkovic wrote:
> On 2016/04/04 15:33:16, f(malita) wrote:
> > I think this change makes sense, but do you mind checking the impact on
> memory?
> > ... 
> >
>
http://www.androidpolice.com/2014/10/20/animation-bonanza-android-5-0-lollipo...
> 
> Thanks for the link.
> Instead of RSS, I used Windows Resource monitor (launch from Task Manager) and
> process "working set" column
> The patch here fixes the same issue in
> http://www.classicdoom.com/maps/plusecs/plu08.htm - this 3 frame GIF used to
> grow working set from 70 to more than 450MB (filling up the
> ImageDecodeController cache with duplicates).
> 
> However, situation is opposite with
>
http://www.androidpolice.com/2014/10/20/animation-bonanza-android-5-0-lollipo...
> The patch here increases working set from 350 to 700MB, as you said.
> 
> I did some debugging. All works fine (no increased working set) if having this
> change (and ImageDecodeController (IDC) is active and patch here applied):
> 
> bool SoftwareImageDecodeController::CanHandleImage(const ImageKey& key) {
>   // TODO(vmpstr): Start handling medium filter quality as well.
> -  return key.filter_quality() != kMedium_SkFilterQuality;
> +  return true;
> }
> 
> @vmpstr - why medium quality handling is different from low quality?
> Is it so that if CanHandleImage returns false - those pixelrefs are cached to
> skia's DM? And if CanHandleImage returns true then SkImages are cached in IDC?
> 
> > 
> > One thing the removed logic provides is an (artificial) cap on
> > degenerate/abusive image resource cache utilization (think videos
masquerading
> > as GIFs).
> > 
> > I tried a similar experiment a few months back (http://crrev.com/1359953002,
> > before ImageDecodeController IINM), and abandoned it because it increased
the
> > footprint significantly: IIRC RSS went from ~400MB to ~900MB for something
> like
> >
>
http://www.androidpolice.com/2014/10/20/animation-bonanza-android-5-0-lollipo...
> > on my Linux workstation (not sure whether we have any suitable tests, I was
> just
> > loading that URL, scrolling around a bit and then observing the process RES
> size
> > in top).
> I have debugged your patch a bit - on the page
>
http://www.androidpolice.com/2014/10/20/animation-bonanza-android-5-0-lollipo...,
> now there are only lazy decoded frames.
> 
> > 
> > Without ImageDecodeController, more live frames meant we were keeping more
> > pixels in Skia's resource cache => given enough frames we were exhausting
the
> > whole budget.
> Yes. Shared memory allocation in SkResourceCache wasn't pinned - and even
fresh
> content would get evicted. Need to analyze where is this allocation.
> 
> > 
> > With ImageDecodeController in place, Skia is no longer managing the lifetime
> of
> > decoded SkImages and IDC is responsible for enforcing its own budget.  But
> > having more lazy decoded frames may still increase the pressure on IDC and
its
> > cache utilization.  And maybe that's perfectly fine (the purist in me would
> > argue that's what the cache is for, so WAI), but then it's a CPU vs. memory
> > trade-off we need to be aware of.
> 
> 
> I have tried to use SkImage::unique() and only clear them (always, not only
for
> > 5MB) in BitmapImage::destroyDecodedDataIfNecessary.
> This would fix issue with
>
http://www.androidpolice.com/2014/10/20/animation-bonanza-android-5-0-lollipo...
> (as those SkImages are outside IDC cache - if in SkResourceCache then SkImages
> are not referenced)
> However, it won't fix http://www.classicdoom.com/maps/plusecs/plu08.htm, in
> BitmapImage::destroyDecodedDataIfNecessary SkImages are not yet referenced by
> IDC cache.
> 
> @vmpstr The issue with increased "working set > 500MB per page" is most likely
> happening with the latest code. I'm running code from 12.03 here (didn't check
> with the latest code).

Closing this issue since I'm working on different fix and have opened another
review thread: https://crrev.com/1925533003/

Powered by Google App Engine
This is Rietveld 408576698