From feeb4327304db5af1c4aa7f77c082bb6527eef5b Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Wed, 28 Jun 2017 21:49:03 +0200 Subject: Don't cache vector images in the surface cache if they are too large. A dimension of 3000 largest size x or y should cover all common caching cases for SVG icons and web app elements, but not caching large vector rasters that would exhaust the cache. This limit is a royal 36MB/element (3000x3000x4) as cap (if the SVG is square). This avoids performance regressions when repeatedly scaling large vector images, but also allows for large SVG backgrounds to be cached. It allows for the bad practice of slapping a large SVG on a site as html background, considering they are likely, even when using large sizes for "responsive" layout, not going to exceed 3000 px in the largest dimension (and if they do, the web designer needs to be slapped with a big trout). --- image/VectorImage.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'image') diff --git a/image/VectorImage.cpp b/image/VectorImage.cpp index 6e3928362..2976f5243 100644 --- a/image/VectorImage.cpp +++ b/image/VectorImage.cpp @@ -931,12 +931,21 @@ VectorImage::CreateSurfaceAndShow(const SVGDrawingParameters& aParams, BackendTy RefPtr svgDrawable = new gfxCallbackDrawable(cb, aParams.size); + // We take an early exit without using the surface cache if + // x or y > maxDimension, because for vector images this can cause bad perf + // issues if large sizes are scaled repeatedly (a rather common scenario) + // that can quickly exhaust the cache. + uint32_t maxDimension = 3000; + bool bypassCache = bool(aParams.flags & FLAG_BYPASS_SURFACE_CACHE) || // Refuse to cache animated images: // XXX(seth): We may remove this restriction in bug 922893. mHaveAnimations || // The image is too big to fit in the cache: - !SurfaceCache::CanHold(aParams.size); + !SurfaceCache::CanHold(aParams.size) || + // Image x or y is larger than our cache cap: + aParams.size.width > maxDimension || + aParams.size.height > maxDimension; if (bypassCache) { return Show(svgDrawable, aParams); } -- cgit v1.2.3