Sussman Lab

This message automatically appears on the site's most-visited pages. If you've found this resource valuable, please consider making a small contribution to keep things running.

Watch the companion video for this post: Compiling LaTeX documents in milliseconds (part 1)

A quick post on this short video. When building NemaTeX, I deliberately postponed a lot of performance tuning. Performance wasn’t really the motivating aspect of this project in the first place – I was having fun thinking about the architecture, and establishing good memory models, and passing Knuth’s conformance suites, etc.

But once the macro profiling from the previous post made the hot spots clear, I thought it was time to substantiate the claim that a modern C++ TeX engine could compile standard LaTeX workloads in milliseconds.

Representative Workloads: From 1 Page to 7,000 Pages

To measure performance realistically, we have to distinguish between two completely different regimes: startup latency on minimal documents versus sustained algorithmic throughput on massive documents.

While there has been a lot of interesting work in the incremental compilation space for LuaTeX, it was obvious to me that there was a lot of space to work on this startup latency problem. In modern interactive editing (such as live-preview or forward/inverse searching in an editor like Neovim), the dominant cost of compiling a small, one-page document is almost entirely engine startup overhead. In traditional engines, every run involves locating font maps, initializing memory tables, and parsing format files from disk. By optimizing the precompiled format (.fmt) loader, I could reduce total startup and compilation time for a standard article-class one-page document down to single-digit milliseconds. “Incremental compilation” just by compiling from scratch every time!

At the opposite end of the spectrum, what happens when you remove startup latency from the equation? To stress-test sustained throughput, I looked at an artificial 7,000-page document filled with realistic text, section headings, mathematical formulas, and page-breaking constraints (the works of Thomas Paine, and the constitution, and a bunch of mathematics, and…). In this regime, the benefits of segregated memory pools and cache-aligned node structures become clearer, as the engine can generate a fully tagged, accessible pdf with modern fonts in ~9 seconds.

In the next posts, I’ll move away from these performance-focused items and shift back to what I consider more interesting architectural considerations!