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

Stuck Forever Eating Memory #369

Open
p30arena opened this issue Oct 12, 2022 · 3 comments
Open

Stuck Forever Eating Memory #369

p30arena opened this issue Oct 12, 2022 · 3 comments

Comments

@p30arena
Copy link

CairoSVG==2.5.2

The Code:

image

The SVG compressed:

test.zip

@liZe
Copy link
Member

liZe commented Oct 12, 2022

Hi!

This image is … strange 😁️. It’s big, it includes a lot of raster images as base64 URLs nested in symbols and drawn by use tags. To be honest, a SVG carefully built to break CairoSVG wouln’t be very different from yours. Even in browsers (and they are among the most optimized pieces of software), it can take more than 5 seconds to be displayed, without the network part!

Technically, it’s not stuck forever (it’s not an endless loop), it’s just incredibly slow, and it tries to eat all the available memory it can find.

If you really want to use CairoSVG to render this document, you can remove these two lines that keep a cache of references and is responsible for the memory hunger. It’s still really slow (more than 1 hour?), the rendering may be broken, but at least it won’t take too much memory.

We will probably not "fix" anything in CairoSVG that could help to render this kind of images. CairoSVG is just not the library you’re looking for 😢️.

(For the record, and if anybody wants to improve this, it doesn’t work because 1- CairoSVG caches all the elements displayed as use tags even if in this case, and contrary to most of the SVG files, they’re never reused and thus take a lot of memory for nothing; 2- use tags referencing a given element for the first time are slow because they create a new tree each time; 3- finding the referenced element in the tree is longer when the element is at the end of the document, so rendering is getting slower and slower as referenced elements are lower in the document.)

@liZe
Copy link
Member

liZe commented Oct 12, 2022

test

(A bit less than one hour on my laptop.)

@p30arena
Copy link
Author

@liZe
aspose handles this image in less than 5 secs!
I rather use Cairo instead of that lib, I'd be happy to hear better news from you.

Cheers

import aspose.words as aw
doc = aw.Document()
builder = aw.DocumentBuilder(doc)
shape = builder.insert_image(svg_path)
doc.save(png_path)

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

2 participants