Dealing with large files that have a lot of images?

I am working on a document that has an auto-generated appendix that contains a large number of large images. There are about 420 images and I have compressed these images down to about 1 MB each. Trying to include all of the images gives me a “memory allocation failed” message. I have tried reducing the number of images to experiment and I have some success, depending on what images I cut out, I can compile a document with anywhere between 50 and 200 images included (The maximum number of images appears unrelated to file size).

Is there any method or trick I can use to deal with this issue? Would it be best to just incrementally compile the document and stitch it together after the fact?

Thanks!

2 Likes

Except dividing the whole file into small parts in source code level, there are many ways:

  • typst compile xxx.typ --pages 1-90
  • typst compile xxx.typ -j 1
  • buy bigger memory cards
typst compile xxx.typ --jobs 1

This is a valid command but it’s also not documented with typst --help. What is it supposed to accomplish?

1 Like

From typst-compile(1) — Arch manual pages

-j, --jobs=JOBS
Number of parallel jobs spawned during compilation. Defaults to number of CPUs. Setting it to 1 disables parallelism

So I don’t think it does really help with this problem.

1 Like

You could use -h on sub-commands too.

typst -h
typst c -h
typst c -j -h

I do not test a benchmark or profile to analyze memory usage, but multiple process instance run simultaneously will use more memory at first glance.

@scdyer Apart from real memory card hardware, u can also set virtual memory in a software way, that will use disk as memory.

Aha I see this parameter is documented under typst compile help.

You mean increase the amount of virtual memory available by increasing the size of the available swap(file).