Forum Bugs

High Memory Usage - am I doing something wrong?

Burstaholic
I'm generating a set of reports that range in size from 1 page to ~300 pages. For some of the larger reports, I'm seeing the PrinceXML process use over 2GB of RAM. I'm running several PrinceXML processes in parallel, so the usage grows fairly large.

Other RAM usage comments I've seen suggest that Prince rarely uses so much RAM, even for documents with thousands of pages. Am I doing something wrong, or is this normal?

The reports have a single small image repeated in each page's header, and otherwise just long tables of text, so I see no obvious culprits.

Thanks!
mikeday
Would you be able to email me (mikeday@yeslogic.com) a sample document that triggers high memory usage? We may be able to reduce it.
Burstaholic
File sent, let me know if you find anything - reducing memory usage for these reports would help us out significantly, whether by changing up the HTML or enhancements to Prince itself.
Vgiattino
Having the same issue. Attempting to pass prince a 25MB HTML page. Prince starts to run and fails. CPU spikes to 100% and game over application quits.
mikeday
Which operating system are you running Prince on? Would you be able to email me (mikeday@yeslogic.com) a sample document for testing?
Burstaholic
This is on Ubuntu Linux 12.04 x64. I've discovered a partial explanation - passing the `--javascript` flag causes memory usage for a given file to approximately quadruple.

Is this expected behavior? We were passing this for all reports since some need javascript run, but apparently we'll need to start being choosy with this flag.

Edited by Burstaholic

mikeday
What kind of JavaScript are you running on the page?
Burstaholic
That's the thing - none whatsoever. The file is as I sent it to you. If I run `prince North Dakota.html` it uses at max about 498 MB of RAM. If I run `prince --javascript North Dakota.html` it uses over 2GB of RAM.

For context, we're evaluating using Prince inside a Node.js report creation service, and that service is currently running all PDF conversions with the `--javascript` flag.

The reports that do have Javascript are building a barcode, but that is only a few of them.

Edited by Burstaholic

mikeday
Okay great, it's all making sense to me now. :)

When JavaScript is enabled, Prince builds up a copy of the DOM for scripts to access (even though in this case there aren't any scripts). While the document is converted to PDF, the JavaScript environment is kept in memory in case there are any post-conversion event handlers waiting to fire (even though in this case there totally aren't). So the memory usage ends up much higher than it should be.

We can attack this problem in several ways. For Prince 9.0 we have slimmed down the DOM, reducing the memory usage to 1.4GB. That's better, but still too high. Hopefully we can discard the extra DOM earlier if there are no post-conversion event handlers, and reduce the total memory usage below 1GB.

In the meantime, probably the only workaround is to disable JavaScript for big documents.
mikeday
We have now released Prince 9, which does try to discard the JavaScript DOM once it is no longer needed, saving memory.