Performance
Measured with scripts/benchmark.py on a 4-vCPU cloud machine with 16 GB of RAM (release build,
default -j, friendly mode; the other formats take up to a third longer, and hard and
hard-95 up to 40% longer, because they draw a picture of every page):
| Pages | Size | Time | Peak memory | |
|---|---|---|---|---|
| Paper (Attention, 2017) | 15 | 2.2 MB | 0.4 s | 78 MB |
| Paper (GPT-4 report) | 100 | 5.2 MB | 0.9 s | 210 MB |
| Textbook (Dive into Deep Learning) | 1185 | 39.5 MB | 6.3 s | 580 MB |
| The same book twice | 2370 | 79 MB | 13.1 s | 1.1 GB |
- Time and memory grow linearly with the number of pages: count about 0.5 GB of memory per
1000 pages of a book with many pictures, in every mode. The HTML is written to the file as its
pictures are drawn, so neither the page nor its pictures are held whole in memory
(
Paper::write_htmlin the library). - Four threads make a single long file about 2.5× faster than one; the renderers and the
document-wide parts of the analysis still run on one thread. To convert many files, run one
process per core with
-j 1: on 4 cores, about 260 papers a minute, at about 53 MB each. - Running more processes than cores only queues them: total throughput stays the same and the memory adds up. Four 1185-page books at once take 19 s and 3.2 GB.
- On a slow machine,
--png-compression fastsaves about a fifth of the time of a book with many pictures (18.3 s → 14.8 s for the textbook on one thread), for an HTML file 28% larger. - The command line uses the mimalloc allocator; the library leaves the choice of allocator to the program that uses it.
Word documents (scripts/word-benchmark.py, same machine, against LibreOffice 24.2 on the
524 documents of the Word corpus, one at a time):
| Word → PDF | kakemono | LibreOffice 24.2 |
|---|---|---|
| All 524 documents (11,657 pages) | 209 s (56 pages/s) | 790 s (14 pages/s) |
| Median per document | 0.12 s, 35 MB | 0.47 s, 192 MB |
| Largest memory | 526 MB | 822 MB |
| Could not convert | 0 | 5 (crashes) |
| Lines / page counts as in Word’s PDF | 95.9% / 89.1% | 79.6% / 72.3% |
The flowing outputs of a Word file (friendly HTML, Word, Markdown, LaTeX, EPUB, JSON) skip the
page layout: 0.01–0.4 s per document, 15–23× faster than LibreOffice’s Word and HTML exports
(.doc → .docx included). One process per core converts about 870 short documents a minute on 4
cores. By size, every format, threads and memory:
docs/WORD-INPUT.md.
Web pages (scripts/web-bench/perf.py, same machine): the 330 pages of the web benchmark
convert to Markdown in 10 ms each (median), 310 ms for the slowest, with 55 MB at most; one
process per core converts about 200 pages a second on 4 cores. Pages written to push the limits:
| Page | Size | Markdown | |
|---|---|---|---|
| 130,000 paragraphs | 48 MB | 1.9 s, 458 MB | 25 s, 2.6 GB |
| One line of 4 million words | 20 MB | 0.7 s, 177 MB | 13 s, 3.6 GB |
| 200,000 boxes of clutter | 12 MB | 0.7 s, 392 MB | 0.6 s, 392 MB |
| 100,000 links in one paragraph | 3.3 MB | 0.6 s, 160 MB | 1.8 s, 400 MB |
| 20,000 headings in a row | 1.5 MB | 0.2 s, 64 MB | 3.6 s, 156 MB |
| 100,000 lines of code | 1.1 MB | 0.1 s, 107 MB | 1.5 s, 390 MB |
Time grows in proportion to the page (tests/scaling.rs checks it), except for elements nested
tens of thousands deep, which html5ever builds in a time that grows with the square of the depth.
A laid-out page holds its text until the PDF is written: the 13,000 pages of the 48 MB page take
about 200 MB of memory per 1,000 pages.
All the numbers, and leads for making it faster, are in docs/IMPROVEMENTS.md.