Repository navigation
Reduce the size of static and animated SVG exports - #3030
Merged
Merged
Conversation
Signed-off-by: Alexander Wang <[email protected]>
- sent from alixander's Codex Signed-off-by: Alexander Wang <[email protected]>
- sent from alixander's Codex Signed-off-by: Alexander Wang <[email protected]>
Signed-off-by: Alexander Wang <[email protected]>
Signed-off-by: Alexander Wang <[email protected]>
Signed-off-by: Alexander Wang <[email protected]>
- sent from alixander's Codex Signed-off-by: Alexander Wang <[email protected]>
Signed-off-by: Alexander Wang <[email protected]>
Signed-off-by: Alexander Wang <[email protected]>
Signed-off-by: Alexander Wang <[email protected]>
… SVGs Signed-off-by: Alexander Wang <[email protected]>
Signed-off-by: Alexander Wang <[email protected]>
Signed-off-by: Alexander Wang <[email protected]>
…ull corpus Signed-off-by: Alexander Wang <[email protected]>
…ont and SVG fallbacks Signed-off-by: Alexander Wang <[email protected]>
Signed-off-by: Alexander Wang <[email protected]>
This was referenced Nov 24, 2026
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
D2 emits smaller standalone SVGs by default. Animation frames share repeated geometry, paint definitions, and identical arrowheads on the same connection. Text stays selectable. Tagged objects keep their drawable children for CSS and event handlers. Custom stylesheets, interactive regions, and independently animated objects keep their existing drawing structure.
Static SVGs omit unused styles and masks. Sketch fills share pencil texture geometry across inks, and isometric drawings share vector patterns, lighting filters, and shadow filters. The icon bundler picks the smaller SVG data URL encoding.
Embedded WOFF subsets retain the same glyph outlines and advances. Boards that rearrange the same characters reuse their font subset. Appendices reuse the diagram's faces and losslessly compress full faces they still need. Custom OpenType/CFF fonts and fonts registered with only a data URL fall back to the full face.
Measured output
Compared with
c6b8a097a. Sizes are bytes. Gzip uses level 9 on each file individually.All 947 ordinary boards got smaller. The median reduction was 3.9%. The comparison renders the root board of each current-format, non-folder end-to-end fixture with the standard 2D SVG renderer. Two archived fixtures use an older target JSON format and were excluded. Across 870 native isometric SVG fixtures, the total fell from 409,970,683 to 380,143,435 bytes.
The animation benchmark uses the guide sources and the cache-stampede headliner. Across seven alternating local CLI runs, the median headliner export took 351 ms on master and 412 ms here, with peak RSS of 83.8 MiB and 87.5 MiB respectively. The ordinary sequence diagram took 17 ms on master and 18 ms here. In a separate 128-frame queue-worker benchmark, preallocating the output and streaming the frame attributes reduced allocation during wrapping from 122.3 MB to 51.3 MB per export compared with the initial PR.
Verification
Compared the midpoint of every frame in all 27 guide animations in Chromium, including all 256 cache-stampede frames. All 1,385 screenshots and visible text selections matched master. Another 189 samples at and around transitions and loop boundaries matched. All 27 resvg still images matched too.
Compared 23 static Chromium renders covering light and dark themes, links and hit testing, text selection, syntax highlighting, Markdown, sketch textures, isometric patterns, and a forced appendix.
Compared arrowheads at high magnification across seven playback times in both themes. Compared the paper texture, a large Markdown panel, and the TPM architecture in Chromium and resvg at two sizes.
Checked a tagged object's CSS override, hover, and delegated click in an embedded diagram. Checked PNG and rasterized PDF output for the icon and appendix cases.
Ran the Go test suite, vet, a WebAssembly build, and targeted race tests. Regenerated the rendered fixtures and manifest hashes.
sent from alixander's Codex