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:
[[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 ofrerun-onfor branding, font, or reference-export hooks so body edits never restart external tools. - Set heavy
generate-outputshooks that scan the entire HTML tree (search indexing, bulk image compression) todev = "skip", running them only intola buildandtola preview. - Store cross-build intermediate caches under
(get-hook).cache-dirkeyed withget-hook --rerun-on-digest, and keep disposable scratch files in(get-hook).temp-dir. - Compare staged outputs against existing files in
before-buildscripts 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 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 duringtola 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 alterspages, re-evaluating pages whose sidebars or nav bars readpages. - Unscoped
query(...)calls (like barequery(heading)) tie each page to global layout state; always scope per-page queries withheadings()orselector(...).within(current-document().location).
Profiling slow steps
Check active hooks, order, and timings with:
tola inspect config --mode dev
tola build --json --prettyWhen 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.