Skip to content

iamharshdabas/typst-throughput-renderer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Typst Throughput Renderer

A high-throughput, concurrent Go renderer for compiling Typst source into PDF bytes.

The project focus is simple: generate PDFs as fast as possible with predictable throughput.

What this project does

  • Accepts Typst source as a string.
  • Uses worker goroutines to compile source in parallel.
  • Calls the Typst CLI (typst compile - -) and returns PDF bytes.
  • Streams successful renders and errors through channels.

Main goal

Optimize for high PDF rendering speed.

Out of scope (for now)

This repository does not aim to be a PDF management system.

It intentionally skips product features such as:

  • PDF identity/tracking workflows.
  • Document lifecycle and storage concerns.
  • Metadata-heavy or business process features.

Requirements

  • Go 1.26+
  • Typst CLI installed and available in PATH

Verify Typst installation:

typst --version

Setup

go mod tidy

Run benchmark (renderer package)

go test -bench=. -benchmem -benchtime=10s -cpu=12 ./renderer

Benchmark results

Measured on: Linux (amd64), AMD Ryzen 5 5600H Date: 2026-04-21

Stress run output (from go run .):

Starting stress test: 1000 runs | 12 workers | 24 buffer
=====================================
Total Time taken : 11.077930344s
Avg Time taken   : 11.00
Success Rate     : 1000/1000
Error Rate       : 0/1000
Throughput       : 90.27 PDFs/sec
=====================================

Benchmark command used:

go test -bench=. -benchmem -benchtime=10s -cpu=12 ./renderer

Observed benchmark output:

goos: linux
goarch: amd64
pkg: github.com/iamharshdabas/typst/renderer
cpu: AMD Ryzen 5 5600H with Radeon Graphics
BenchmarkRenderer/W:6/Ratio:2x(Buf:12)-12             754  15696553 ns/op  0.12 MB/s  179758 B/op  115 allocs/op
PASS
ok      github.com/iamharshdabas/typst/renderer 13.514s

Notes:

  • Peak measured throughput in this repo: 90.27 PDFs/sec on a 1000-PDF stress run.
  • Average latency during that run: about 11 ms/pdf.
  • Thermal throttling directly affects sustained throughput.

How renderer works

flowchart TD
    A[Caller invokes CreatePDF with Typst source] --> B[Source pushed to input channel]
    B --> C[Worker goroutine reads source]
    C --> D[Run typst compile - -]
    D --> E{Compile success?}
    E -->|Yes| F[Send PDF bytes to OutputChan]
    E -->|No| G[Send error to ErrorChan]
    F --> H[Consumer handles rendered PDF]
    G --> I[Consumer logs/handles failure]
    H --> J[WaitAndClose drains and closes channels]
    I --> J
Loading

Example stress run

main.go demonstrates a stress test that:

  • Loads Typst source from renderer/file.typ
  • Uses runtime.NumCPU() workers
  • Submits 1000 render requests
  • Reports success/error counts and throughput

Run it with:

go run .

Performance tuning tips

  • Start with workers = runtime.NumCPU().
  • Keep channel buffers near workers * 2 as a baseline.
  • Benchmark with your real Typst templates, not only synthetic/simple docs.
  • Track error rate while increasing throughput.

Current status

This project is effectively complete for its goal: maximizing Typst-to-PDF throughput.

No further work is planned. Treat this as a focused performance experiment, not a full PDF platform.

About

High-throughput concurrent Go renderer for Typst-to-PDF generation, optimized for sustained rendering speed (up to 90.27 PDFs/sec in stress tests).

Resources

Stars

Watchers

Forks

Contributors