Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Satori generates a circle object for gradient, which caused high memory in Resvg #631

Open
ducan-ne opened this issue Jul 19, 2024 · 0 comments

Comments

@ducan-ne
Copy link

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
image

Refer from author of Resvg (RazrFalcon/resvg#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",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant