Skip to content

Memory issue with creating a doc with a lot of images #861

@rsshilli

Description

@rsshilli

I'm creating a document that has 750+ pages where each page has a different screenshot. The total doc size is 48 MB and it takes ~4 mins to create, which seems fine. What's not fine is that it take ~6 GB of memory to create this 48 MB file.

At first I thought I had the same problem as #728 but when I tried @blikblum's branch which includes both the new es6 conversion and #728 I found that it didn't help at all.

I've figured out a fix for it. The problem is in the PNG zlib decrypting. The doc.image() method is returning right away, and if you create a lot of pages and add a lot of images, the image processing piles up on itself until it's literally trying to decode hundreds of images at once. Unfortunately it seems the image decoding takes a few x more memory and when it happens all at once it gets out of hand.

With my fix, the 6 GB of memory went down to about 100 MB of memory. The downside though is that now doc.image() returns a promise instead of the doc, which means they can't be chained together anymore.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions