Bug 230886 - [GPU Process] REGRESSION: Drawing a large SVG image on a canvas may take too much memory
Summary: [GPU Process] REGRESSION: Drawing a large SVG image on a canvas may take too ...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Canvas (show other bugs)
Version: Other
Hardware: iPhone / iPad Other
: P2 Major
Assignee: Said Abou-Hallawa
URL: https://codepen.io/Ziriax/full/LYLgYxp
Keywords: InRadar
: 231796 (view as bug list)
Depends on:
Blocks:
 
Reported: 2021-09-28 02:45 PDT by kaput.sts
Modified: 2021-11-15 09:36 PST (History)
13 users (show)

See Also:


Attachments
Simple test case (Should show a green rectangle) (874 bytes, text/html)
2021-10-22 15:58 PDT, Said Abou-Hallawa
no flags Details
Patch (6.38 KB, patch)
2021-10-22 16:09 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description kaput.sts 2021-09-28 02:45:52 PDT
It seems that when downscaling a HTML canvas by factor F, and drawing an image with SVG source, upscaled by factor F, iOS 15 Safari crashes when F is large enough, even though these two factors should cancel out (1/F * F = 1).

I think it will draw the SVG to an intermediate texture F times the size of the SVG, in this case (F*1000)^2 pixels => kaboom.

This is a regression because it works on all other browsers, and works fine in iOS 13 and 14 Safari.
 
To reproduce, visit https://codepen.io/Ziriax/full/LYLgYxp
Comment 1 kaput.sts 2021-09-28 02:50:04 PDT
It seems Safari TP on OSX also crashes
Comment 2 Sam Sneddon [:gsnedders] 2021-09-28 09:31:15 PDT
GPU process, maybe?
Comment 3 Radar WebKit Bug Importer 2021-09-28 10:20:39 PDT
<rdar://problem/83628607>
Comment 4 Alexey Proskuryakov 2021-09-29 13:12:57 PDT
I cannot reproduce this on macOS 12 beta with Safari 15.1 on Apple Silicon, nor with STP 132, for what it's worth.
Comment 5 Sam Sneddon [:gsnedders] 2021-09-30 05:00:12 PDT
I can see vastly higher memory usage on macOS 12 beta with Safari 15.1 on Intel and vastly worse performance than Firefox Nightly or Chrome Canary. On the whole my assumption is the crash is "simply" OOM.

I'd presume that Firefox and Chrome are cancelling out the factors and therefore they don't actually do anything.
Comment 6 Simon Fraser (smfr) 2021-09-30 10:12:13 PDT
GPU Process forced us to draw SVGs into an image buffer and then draw that to the canvas. That's probably the cause of the regression.
Comment 7 kaput.sts 2021-10-04 04:15:38 PDT
I see, that was what I expected.

So some extra logic should be added to compute the minimal size of such an intermediate texture. If the world canvas transform is known, and the dimensions of the canvas, that is not too difficult IMHO?
Comment 8 Said Abou-Hallawa 2021-10-22 15:58:42 PDT
Created attachment 442208 [details]
Simple test case (Should show a green rectangle)
Comment 9 Said Abou-Hallawa 2021-10-22 16:09:26 PDT
Created attachment 442212 [details]
Patch
Comment 10 EWS 2021-10-22 21:07:19 PDT
Committed r284740 (243449@main): <https://commits.webkit.org/243449@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 442212 [details].
Comment 11 Said Abou-Hallawa 2021-11-02 14:05:47 PDT
*** Bug 231796 has been marked as a duplicate of this bug. ***
Comment 12 Roman Nikitin 2021-11-09 06:24:57 PST
Could you tip when it will be in the new safari version?
Comment 13 Sam Sneddon [:gsnedders] 2021-11-15 09:36:07 PST
(In reply to Roman Nikitin from comment #12)
> Could you tip when it will be in the new safari version?

Apple does not comment on future releases.