Skip to content

perf: share one font store per font configuration across the process - #56

Merged
evolvedlight merged 1 commit into
evolvedlight:developfrom
swisspost:perf/shared-font-store
Oct 17, 2026
Merged

evolvedlight merged 1 commit into
evolvedlight:developfrom
swisspost:perf/shared-font-store

Conversation

@msallin

@msallin msallin commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

Every TypstCompiler scanned the system fonts and built its own FontStore. That scan is most of what creating a compiler costs, so the static one-shot helpers (TypstCompiler.CompilePdf(source) and the like) paid for it on every call. Each live compiler also kept its own copy of every font it loaded.

Font stores are now cached for the whole process, keyed by IncludeSystemFonts and the font directories. SystemWorld reads its font book straight from the shared store, so the separate per-world copy of the book is gone.

Measured with system fonts enabled, creating a compiler, compiling a short PDF and freeing it, release build on Windows:

1st call 2nd call 3rd call
before 79 ms 71 ms 77 ms
after 74 ms 1.8 ms 1.4 ms

Trade-offs, also noted in the release notes and on the Fonts record:

  • A font installed, or added to a font directory, after a configuration was first used is not seen until the process restarts.
  • Fonts a configuration has loaded stay in memory after its last compiler is disposed. EvictCache() does not release them.

Tests: new unit tests check that worlds with the same configuration share a store, that the store outlives its worlds, and that different configurations get different stores. cargo test --release passes, and so do all 80 .NET tests.

Every compiler scanned the system fonts and built its own FontStore. The
scan is most of what creating a compiler costs, so the one-shot helpers
paid it on every call, and each compiler kept its own copy of every font
it loaded.

Stores are now cached process-wide, keyed by whether system fonts are
included and the font directories. With system fonts enabled, create,
compile and free of a short document went from 71-77 ms to 1.4-1.8 ms
after the first call. A font installed after a configuration was first
used is not seen until the process restarts.
@evolvedlight
evolvedlight merged commit 58bcb1d into evolvedlight:develop Oct 17, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants