Repository navigation
perf(paint): share static font instances across renders - #444
Conversation
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Downstream measurement: go-slides v0.26.0 with this branch (1aa085b) swapped in through a
This undoes the regression bisected in go-slides/slides#117. Peak memory goes from about 2.1 GiB to 177 MiB, back to the level before engine v0.45.10. On one core, the PDF is now about 2.8× faster than marp-cli. The PDF is smaller because each page used to embed its own instance of the font. |
Closes #443
Refs go-slides/slides#117
paint.Fonts.glyphFontbuilt a static instance of a variable font(
opentype.(*Font).Instance) into a cache that lives on the per-renderFonts.A vector export creates one
Fontsper page (vectorpage.go), so every pagerebuilt every instance.
The instance cache is now process-wide (
paint/sharedinstances.go), thecompanion of the shared parsed fonts from PR 291:
caller retries, and the page still draws the default master as before);
sync.Oncemakes them wait for one build; themap is behind a mutex;
Fonts.instancesstays as a lock-free per-render view.Output is unchanged: the same instance bytes, the same fallback.
Tests (
go test -race ./paint .green):TestNewFontsShareInstances(twoNewFontsbuild once, counted through theinstantiateseam, clamped weightsshare),
TestSharedInstancesConcurrent(16 parallel pages, one build),TestSharedInstancesBounded, and the existingTestGlyphFontInstance.BenchmarkGlyphFontPages: a cold 20-page export, oneNewFontsper page, 4weights of a variable font each (Outfit-wght);
-count=5, M4 Max, allocationcounts are the stable column.
(Before, each page re-instanced; after, only the first page does: 20x fewer
allocations.) README updated.
🤖 Generated with Claude Code