On 4 December the staging worker of a CRM froze. The CRM printed its quotes with a headless Chrome that ran next to the app on a small 2 GB cloud instance with no swap, and there was no memory left. Seven other documents were drawn by Prawn, a Ruby PDF library, inside the Rails process itself.
By 11:42 UTC the next day every PDF the CRM makes was printed by pdfblaze, a Rust program I had forked from an open-source engine the evening before. The Chrome container was gone, and so was Prawn. The CRM's 13 quote templates print in a median of 21 ms and about 26 MiB each, where a cold Chrome needed about 976 MiB for one document. A 1,000-message chat transcript went from 16.5 s to 0.8 s. Between the fork and production there were 16 commits, four releases and a security audit with 13 findings. Fork commit to production: under 20 hours.
This post is the overview: what printed the PDFs before, how I chose the engine, what I changed in the fork, and what the numbers are, including the ones that are not flattering. The series goes deep on each part:
- Printing a CRM's PDFs without Chrome (this post)
- Choosing a PDF engine by measurement
- Halving the heap of a 119-page invoice
- An audit and two releases in one day
- A ten-kilobyte logo that crashed the renderer
- The pool that handed one tenant's PDF to the next
- Replacing Prawn: seven documents, one engine
- Shipping a Rust binary you can verify
What was printing the PDFs
Two printers, with two different problems.
Quotes: a headless Chrome. A long-lived Chrome container with a 768 MiB limit ran beside the app and turned every quote's HTML into a PDF. Warm, it was quick enough: a median of 275 ms per template. But it only grew. Over 52 renders in a row in my comparison runs, the warm Chrome service went from 1,252 MiB to 9,404 MiB. Starting a fresh Chrome for each document stops the growth and costs more up front: a median of 976 MiB and 0.864 s for a one-page quote.
On staging that growth met a small machine. During the freeze the Chrome container went from 105 to 473 MiB while the jobs container sat at about 730 of its 800 MiB. A deploy starts the new container before it stops the old one, so for a moment both copies run. Getting the machine back took a stop and start of the instance.
Everything else: Prawn inside Rails. Invoices, contracts, signed contracts, receipts, payouts, chat transcripts and the plain quote were each drawn by Ruby code with Prawn, in the same process that served web requests and ran jobs. A big document grew that process by 49.6 to 389.1 MB. The 1,000-message transcript took 16,468.4 ms and grew it by 389.1 MB. Prawn also printed Arabic as "?" or with its letters reversed.
The constraint. A bigger server would have stopped the freeze. I chose not to buy one. A printer that needs a gigabyte for a one-page quote will need the next size up as well, and the one after that. The printer had to fit the machine.
Choosing an engine
Part 2 has the whole survey. The short version: WeasyPrint came first. I built a version of the quote with it, and its look was approved. Then I measured it: 1.09 s and 80 MiB for a one-page quote, median of four, a fresh process each, on a Mac. Fine for one quote, poor for a worker that prints them all day.
So I measured eight engines on the same quotes, the same way:
| Engine | Time per quote | Peak memory | Verdict |
|---|---|---|---|
| WeasyPrint 70 | 1.09 s | 80 MiB | too slow for the worker |
| The base engine, 1.3.0 | 0.022 s | 25 MiB | picked, and forked |
| ferri-pdf 0.3.0 | 0.069 s | 30 MiB | runner-up |
| Typst 0.15 | 0.028 s | 26 MiB | every template would need a rewrite |
| sghtmltopdf | 0.041 s | 16 MiB | broke the layout; no right to left |
| fullbleed | 0.118 s | 33 MiB | Arabic letters not joined |
| Fulgur | 0.18 s | 32 MiB | right-to-left table not mirrored |
| PlutoPrint | 0.31 s | 36 MiB | no grid |
The engine I picked is an open-source Rust engine (MIT/Apache-2.0). It printed the quotes in 20–24 ms at 24–26 MiB, scored 94–100 on fidelity against Chrome, and was the fastest of the eight while getting Arabic and right-to-left tables right.
I forked it rather than depending on it. The CRM needed changes on its own schedule: the memory work, the audit fixes and a release pipeline it could verify all landed within a day, and the CRM pins the exact binary it runs. pdfblaze is that fork. The base engine's copyright stays in LICENSE-MIT.
The engine already did most of the hard parts before I touched it: page breaks inside layout rather than after it, PDF/A and PDF/UA output, PAdES signing, a framed worker protocol, a Linux sandbox, and a Web Platform Tests run in which 70.4% of the tests it runs pass. That is the base engine's work, not mine. Every version from 0.1.0 to 1.3.0 in the CHANGELOG is its history. My part starts at the fork commit and is the rest of this series.
From fork to production
1 · 12-04 · rollout
The staging worker freezes
Quotes were printed by a long-lived headless Chrome container on a small 2 GB instance with no swap. Chrome grew from 105 to 473 MiB, the jobs container sat near its cap, and getting the machine back took a stop and start. I chose not to buy a bigger server: the printer had to fit.
The fork commit is at 16:00 UTC on 4 December. Production went live at 11:42 UTC on 5 December. In between, roughly in order: memory work and a first release, a layout fix, a security audit of that release, two releases that fixed what the audit found, and the rollout.
What I changed in the fork
| Change | What it gave | Part |
|---|---|---|
| Shrink and clear buffers, a smaller DOM node, shared styles for alike anonymous blocks, a web font held once | Heap on a 2,000-row, 119-page invoice 65.0 → 34.5 MB; peak RSS 114 → 86 MiB; each node 152 → 72 bytes | 3 |
| Fat LTO for release builds | 4–5% faster, binary 28.0 instead of 30.5 MB | 8 |
| Size flex image tiles from the right box (1.4.1) | A 56 px logo tile with 6 px padding is 144 px wide, not 168 | below |
| Write to standard output on Windows | A pipe that failed with os error 87 works | — |
| A depth limit for nested objects in PDFs used as images (1.4.2) | A 10 KB file posing as a logo no longer crashes the process | 5 |
| Stop a worker on any interrupt, check answer ids (1.4.2) | The documented pool no longer hands one caller's PDF to the next | 6 |
| CSS counters and multi-column layout obey the limits (1.4.2) | A 47 KB input can no longer run for 29.3 s under a 1 s limit | 4 |
| Release jobs split: build with read-only tokens, a separate job attests | Signed provenance and SBOMs per artifact; build jobs cannot write | 8 |
| Drop the PHP and Laravel package | 147 files; 15,388 lines removed; one less thing to secure | — |
The memory work had one rule. Every change was checked against 668 test PDFs, which stayed byte-identical from the fork commit to the end. A counting allocator in the test suite fails if the peak heap of a 600-row table creeps back past its bound. Part 3 has the steps. The commit messages give the heap as 65.0 → 47.5 → 42.2 → 36.8 → 34.5 MB, and the CHANGELOG's end-to-end heap profile gives 63.5 → 33.1 MiB.
The logo fix came from the comparison below. Three templates differed from Chrome by about 3% of their ink, all for one reason: a logo with padding came out 24 px too wide. After 1.4.1 those three differ by 0.0%.
Against Chrome: 13 quote templates
The CRM ships 13 starter quote templates, from a one-line quote with no logo to a three-page Arabic and English one. I printed each with pdfblaze (three fresh processes, median) and with the warm Chrome service (median of three), on a busy laptop, and compared the pages at 80 dpi.
- pdfblaze 1.4.0, fresh process
- chrome 158, warm service
- classic1 pagepdfblaze 19 mschrome 268 ms
- us-estimate1 pagepdfblaze 21 mschrome 240 ms
- au-gst1 pagepdfblaze 21 mschrome 279 ms
- de-angebot1 pagepdfblaze 19 mschrome 282 ms
- in-gst2 pagespdfblaze 22 mschrome 241 ms
- ae-bilingual1 pagepdfblaze 21 mschrome 260 ms
- proforma-hindi1 pagepdfblaze 24 mschrome 275 ms
- boxed-quotation1 pagepdfblaze 22 mschrome 315 ms
- long-605 pagespdfblaze 33 mschrome 316 ms
- one-line-no-logo1 pagepdfblaze 18 mschrome 275 ms
- long-names-fr2 pagespdfblaze 21 mschrome 238 ms
- arabic-rtl3 pagespdfblaze 29 mschrome 550 ms
- letterhead-letter2 pagespdfblaze 36 mschrome 415 ms
Median 21 ms for pdfblaze and 275 ms for a Chrome that was already running: about 13× faster, before counting Chrome's start-up.
| pdfblaze | Chrome | |
|---|---|---|
| Time per template, median | 21 ms, a new process each | 275 ms warm; 0.864 s cold |
| Memory per template | 24–36 MiB, median 26 | 976 MiB cold, median |
| PDF bytes, all 13 | 523,724 | 1,066,198 |
| PDF bytes, median | 36,896 | 56,662 |
The verdict across the 13 was 9 that match, 4 with small differences, 0 broken. The largest difference is not layout: long-names-fr differs by 67.2% of its ink because the test gave Chrome a Georgia font and gave pdfblaze none.
Two runs of the same comparison, on 1.4.0 and on 1.4.1, gave medians of 21 ms and 30 ms. Both ran on a laptop with other work going on, and nothing in the files explains the gap, so the honest range is 19–38 ms per template. Re-run today on 1.4.1 and 1.4.3, seven runs each, the 13 templates took 311.6 ms and 304.6 ms in total, with every page pixel-identical at 80 dpi between the two versions.
Here is what "small differences" looks like on two of the templates:


boxed quotation: 0% of ink differs, rounded. Two pixels differ, at the corners of the logo tile. Everything else matches at this resolution.
Against Prawn: seven documents
The seven Prawn documents moved in one change. On a laptop (M2 Pro), 7 runs each, median, the old engine inside Rails against pdfblaze 1.4.3 in its own process:
| Document | Old | pdfblaze | |
|---|---|---|---|
| Invoice, 1,000 lines | 1,921.4 ms | 227.1 ms | 8.46× faster |
| Payout, 1,000 entries | 2,500.5 ms | 478.3 ms | 5.23× faster |
| Chat transcript, 1,000 messages | 16,468.4 ms | 801.7 ms | 20.54× faster |
| Quote, 3 lines | 18.4 ms | 58.6 ms | slower |
Twelve of the 13 measured cases got faster. The 3-line quote got slower, because a process start replaced a call inside the running app. Part 7 has all 13, how large each document can get before pdfblaze refuses it, and the production deploy that failed the first time.
What the audit changed, measured today
The audit of 1.4.1 found 2 High, 3 Medium, 4 Low and 4 Info findings. Two of the Mediums were the same kind of bug: a time limit or memory budget that a small input could walk straight past. Measured today on the released 1.4.3 (macOS arm64, median of 3):
| Case | Before, on 1.4.1 | 1.4.3 |
|---|---|---|
3,000 counters × 3,000 elements, --time-limit 1 | 29.3 s, 702 MiB; the limit ignored | stops at 1.35 s (limit.time), peak 607 MiB |
the same, --memory-budget 64 | the budget ignored | stops at 0.42 s (limit.memory), peak 358 MiB |
400,000 words in 1,000 columns, --time-limit 1 | still running at 120 s | stops at 1.08 s, peak 314 MiB |
pdfblaze render counters.html -o out.pdf --time-limit 1
A document that stops this way fails with a reason the caller can read, not a killed process. Part 4 is the audit. Its guard tests were checked by taking each fix out and watching the test fail.
What is still open
- No production numbers yet. On staging the newest real record of each of the 8 document kinds printed in 78–412 ms, warm. I have no latency or memory figures from production since it went live.
- The memory budget is not a hard cap. It estimates what a document holds and
stops the document; it does not cap the process. Peaks still reach several times
the budget before the stop: 358 MiB at a 64 MiB budget above, 415–583 MB at the
largest CRM documents under 256 MiB. On Linux,
--memory-limitis the hard cap, and the CRM does not set it yet. - Copying Hindi or Arabic text out of the PDF gives the wrong characters. The page looks right; the text layer behind shaped letters is wrong.
- No veraPDF run. pdfblaze writes PDF/A, but I have not validated the CRM's output with veraPDF.
- The 3-line quote is slower, 18.4 → 58.6 ms, as above.
- Counters with no limits set are still expensive. At 3,000 × 3,000 they take 5.8 s and 1.7 GB on 1.4.3. The fix makes the limits work; it does not make the case cheap.
What I'd do differently
- Measure on a quiet machine. Two runs of the same 13 templates gave medians of 21 and 30 ms, and I cannot say which is right. A laptop with a load average of 12 is not a benchmark machine.
- Audit before the first release, not after it. Two releases of the fork were out before anyone had tried to break it on purpose, and the audit found two High findings.
- Set the hard memory cap on day one. The budget did its job on every test I ran, and the real peak still went past it every time.
- Read the deploy's health-check settings before the big deploy. The first production deploy failed on a check that ran every 10 seconds, and nothing in pdfblaze had to change to fix it. Part 7 has the details.
The code, the releases and the CHANGELOG are public: github.com/sundarshahi/pdfblaze, releases, CHANGELOG. If you read one more post, read part 3: it is the work that made the engine fit the machine.