Performance

Once a site reaches hundreds of pages—with CSS compilation, search indexing, or generated docs—tola dev and tola build time comes mainly from two places: hooks re-running on unrelated edits and repeated work inside the Typst Bundle.

Hook reuse

In tola dev, hooks default to dev = "run" on every save. Switch deterministic before-build and generate-outputs hooks (that do not depend on wall-clock time or network state) to dev = "reuse" and narrow rerun-on:

toml
[[hooks.before-build]]
name = "styles"
nu = "tools/styles.nu"
dev = "reuse"
rerun-on = {
  include = ["styles", "**/*.typ"],
  exclude = ["public", ".tola", "vendor", "generated", "content/*/docs/reference/**"],
}
generates = ["generated/styles/site.css"]
  • Keep content/ out of rerun-on for branding, font, or reference-export hooks so body edits never restart external tools.
  • Set heavy generate-outputs hooks that scan the entire HTML tree (search indexing, bulk image compression) to dev = "skip", running them only in tola build and tola preview.
  • Store cross-build intermediate caches under (get-hook).cache-dir keyed with get-hook --rerun-on-digest, and keep disposable scratch files in (get-hook).temp-dir.
  • Compare staged outputs against existing files in before-build scripts and skip overwriting when identical so downstream timestamps stay untouched.

Template overhead

Although Typst memoizes file loads and function calls across the Bundle, template code still evaluates per page:

  • Load large JSON files and build lookup dictionaries once at module top level instead of calling json(...) inside every page template.
  • Avoid quadratic 𝑂(𝑁2) scans inside high-frequency rules like show heading (for instance recomputing a page’s entire slug deduplication table per heading). Take a fast path (str(section.label)) whenever an explicit <label> exists.
  • Deduplicate shared Mermaid or vector graphics by content hash (@tola/hash) via Bundle-level asset aggregation so each unique figure compiles once.
  • Gate dual HTML + PDF output behind metadata (pdf: true) instead of typesetting every page as PDF during tola dev.

Incremental bounds

Typst’s incremental memoization caches function calls and file dependencies inside the single site Bundle:

  • Prose-only edits that leave tola-meta, shared navigation, and backlinks unchanged let unaffected pages reuse cached evaluations.
  • Changing title, order, or adding/removing files alters pages, re-evaluating pages whose sidebars or nav bars read pages.
  • Unscoped query(...) calls (like bare query(heading)) tie each page to global layout state; always scope per-page queries with headings() or selector(...).within(current-document().location).

Profiling slow steps

Check active hooks, order, and timings with:

sh
tola inspect config --mode dev
tola build --json --pretty

When parallel hooks contend for CPU or disk I/O, cap [build].hook-jobs in tola.toml or set [build].par-hooks = false while debugging order issues. Pass tola dev --no-reuse to verify behavior without cached hook outputs.

Search this site

Use the arrow keys to move through results.

Type to search.