satori
satori copied to clipboard
Satori generates a circle object for gradient, which caused high memory in Resvg
Bug report
Satori generates a circle object for gradient, which caused high memory in Resvg
Description / Observed Behavior
With this given simple file (Playground), Satori generate a circle in svg for creating circle gradient (I don't know actually how it works), which consumes 170mb of memory when rendering it to PNG with Resvg.
Reproducible script: https://gist.github.com/ducan-ne/709bbbf3965c6cc4786660ad17e5ebe0
Refer from author of Resvg (https://github.com/RazrFalcon/resvg/issues/792), this created a circle 4180x4180px in dimensions which caused large memory consumption during rendering. Dimension = circle.radius * 2
<circle cx="1080" cy="1790" width="1080" height="1790" r="2090.5740838343904" fill="url(#satori_r2adial_id_0)" mask="url(#satori_mask_id_0)" />
This circle is 4180x4180px in dimensions. Or 4646x4646px with --width 1200. That's 4646 * 4646 * 4 = 86MB for the image/layer + 4646 * 4646 * 1 = 22MB for the mask + 1200 * 1989 * 4 = 10MB for the pattern. Yes, it can be drastically optimized in your case by having non-raster rectangular masks, but this isn't supported yet.
Expected Behavior
In typical environments like Server or Serverless it'd not be an issue, but I'm running in an isolated environment such as edge runtime where the memory is limited to 128mb. Hopefully we can find a way around that so we can cover more use cases than just small images like og image
Reproduction
https://og-playground.vercel.app/?share=XZDBTsQgEIZfhYwx3SaobXdPZN2L8eDdYy9QBopSaCi1Nk3fXdiNB01ImPn-ycz8s0HnJQKDszRfrSNkiqvF523LsTTTaPnKSKEsfhc0s8XI2CdSV9X9jfRodB__IMG7Tx387OSLtz4k7U4p9V97G7jGpAUuDbcPOv_o4qEzobNIeCQhdybCx-gHSoIWh4qS_EpSPaZpNKOmpqQ5UXI6liStkHlZtG7fW3epm2Przk_J26V1QMGP0Xg3AdvgagRY3VQVhZuH30yimDUwxe2EFHDwH-Z9HfOV4nLNUiflXXwdBEpgMcy4U4hcpIoerfWLD1bC_gM https://gist.github.com/ducan-ne/709bbbf3965c6cc4786660ad17e5ebe0
Additional Context
"satori": "^0.10.14",