Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,15 @@ builds reproducible: whatever is deployed is exactly what gets compiled.

You can easily use this inside of an ASP.Net Server (just ensure you lazy load and cache the TypstCompiler to reduce from 40ms to around 3ms for a normal compile).

A cached compiler stays current: every compilation reads the template, its imports and its data
files from disk again, so redeploying a template takes effect without restarting the process. Two
things follow from that. Replace template files atomically — write a temporary file and rename it —
because a compilation that lands halfway through a plain overwrite renders the half-written file.
And a warm compilation now costs one stat and one read per file it touches, so a template split
across many files is measurably more expensive to recompile than a single one.
A cached compiler stays current: every compilation checks the template, its imports and its data
files on disk, so redeploying a template takes effect without restarting the process. The check
is one stat per file the compilation touches, and a file is read again only when its size or
modification time has changed. Two things follow from that. Replace template files atomically,
by writing a temporary file and renaming it, because a compilation that lands halfway through a
plain overwrite renders the half-written file. And a deployment that rewrites a file while keeping
both its size and its modification time, such as a copy that preserves timestamps over a file of
the same length, is not noticed; a file modified within the last two seconds is always read, so
an ordinary write is safe even on file systems with coarse timestamps.

## Prerequisites

Expand Down
2 changes: 1 addition & 1 deletion RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## [Unreleased]
### Fixed
- Fixed a stream from `document.OpenOutputStream()` leaving the rendered document in `ArrayPool<byte>.Shared`. Only the byte-array reads were overridden, so span-shaped and asynchronous reads, and `CopyTo`, fell through to `Stream`, which stages the bytes through a rented array and returns it to the pool without clearing it. The next component in the process to rent from that pool could read the document back. The reads and the copy now go straight from native memory, which also removes a second copy of every byte: a 4 MiB span read measured 0.767 ms before and 0.274 ms after.
- Fixed a compiler reused across compilations never seeing a change made to the files it reads. The main file and every import were read on first access and then kept forever, so a cached `TypstCompiler` — which the README recommends, because it takes a compile from around 40ms down to 3ms — went on rendering the template it had read at startup, with no error to show for it. Every compilation now starts by invalidating the file slots, the way `typst-cli` does between watch runs, so a template redeployed underneath a running process takes effect. Files whose content has not changed are recognised by their hash and are not parsed again, and a document passed in as a string is unaffected: there is no file behind it. Two consequences worth knowing about: templates should be replaced atomically, because a compilation that lands halfway through a plain overwrite now renders the half-written file; and a warm compilation costs one stat and one read per file it touches, so a template split across many files is measurably more expensive to recompile than a single one.
- Fixed a compiler reused across compilations never seeing a change made to the files it reads. The main file and every import were read on first access and then kept forever, so a cached `TypstCompiler`, which the README recommends because it takes a compile from around 40ms down to 3ms, went on rendering the template it had read at startup, with no error to show for it. Every compilation now starts by invalidating the file slots, the way `typst-cli` does between watch runs, so a template redeployed underneath a running process takes effect. A file whose size and modification time are unchanged is not read again, so a warm compilation costs one stat per file it touches; a file that is read but hashes the same is not parsed again; and a document passed in as a string is unaffected: there is no file behind it. Two consequences worth knowing about: templates should be replaced atomically, because a compilation that lands halfway through a plain overwrite now renders the half-written file; and a rewrite that keeps both the size and the modification time of a file, such as a timestamp-preserving copy over a file of the same length, is not picked up. A file modified within the last two seconds is always read, which covers rewrites within one tick of a coarse file system clock.
- Fixed an input path in a subfolder aborting the process instead of compiling. The path was handed to Typst verbatim, and a Typst virtual path only accepts forward slashes, so on Windows an ordinary relative path such as `templates\letter.typ` panicked inside a native call and took the host process down with it. Paths are now resolved against the project root before being converted, and a path that genuinely leaves the root reports an error instead of panicking. Note that the root is matched against an absolute input path textually, so on Windows both have to be spelled with the same casing.
- Fixed `ua-1` (PDF/UA-1, the accessibility standard) being rejected by `pdfStandards`. The accepted names are now taken from `typst_pdf::PdfStandard` itself, so every standard Typst supports is accepted, including ones added by later Typst releases. The documented `v-` prefix on plain PDF versions still works, and applies only to them: `v-a-2b` is not a spelling of `a-2b`.

Expand Down
Loading
Loading