Repository navigation
svg: collect font and palette usage while drawing - #2995
Merged
Merged
Conversation
- sent from alixander's Codex
- sent from alixander's Codex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Human
AI
The renderer now records font glyphs and theme classes while drawing common shapes, connections, class rows and SQL tables. This avoids decoding the completed SVG to rediscover those values. Recording glyphs in drawing order preserves the font subset bytes.
Objects containing arbitrary SVG still go through the XML decoder so nested text and inherited styles keep their existing semantics. Adjacent objects share a decoder pass, and separated fragments reuse its input buffer. A palette fallback can run independently of the font collector. Sketch renderings and custom stylesheets retain their existing collection behavior.
Performance and tradeoffs
For an eight-actor sequence with 1,000 messages, median warm SVG time fell from 24.4 to 16.3 ms across 40 paired label edits. Compile plus render took 36.0 to 29.5 ms. First-call SVG time in a fresh process went from 25.8 to 18.5 ms across 20 pairs. Process startup is outside those timers.
The geometry and output-mode benchmarks below time the full
d2svg.Rendercall with a precomputed layout and warm font caches. Each workload had 12 paired samples on an Apple M4 with Go 1.27.4. The time-change column shows the median within-pair change and a 95% paired bootstrap interval. Time and allocation columns show standalone medians. MB is cumulative allocation volume per render.An early version allocated about 40% more on the 256-oval board by opening a reader per shape. Ovals now report their classes directly. Alternating flat and 3D objects also exposed the cost of allocating a fresh XML input buffer per fragment. Reusing that buffer brought the final allocation volume to 7.56 MB against 8.00 MB on the parent. Three workloads had small or noisy timing changes in the first run. A separate, longer run used 24 paired samples per workload and 30 to 150 renders per sample. Its paired time changes were custom stylesheet -0.8% (-6.3% to +7.3%), Markdown +0.3% (-3.2% to +7.2%), sketch mode +1.5% (-6.8% to +4.6%). Intervals are 95% paired bootstrap estimates on this shared machine.
The extra maintenance cost is keeping the writer's font and class callbacks consistent with the XML collector as drawing code changes. The stripped native CLI grew by 320 bytes. The raw release-style TinyGo WASM grew by 7,771 bytes. Its Brotli-compressed download grew by 2,285 bytes (5,999,098 → 6,001,383 bytes).
Verification
go test -race ./d2renderers/d2svg ./d2themespassed.