Skip to content

Reduce the size of static and animated SVG exports - #3030

Merged
alixander merged 16 commits into
masterfrom
perf/reduce-svg-output
Nov 24, 2026
Merged

alixander merged 16 commits into
masterfrom
perf/reduce-svg-output

Conversation

@alixander

@alixander alixander commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

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.

Example SVG before SVG after Gzipped before Gzipped after
Cache stampede, 256 frames 3,292,804 2,138,407 143,591 66,509
Pencil shading 1,070,720 552,233 46,267 39,764
Connection pulse 134,028 85,811 14,747 8,788
Static link and tooltip with forced appendix 676,806 159,930 274,736 118,092
Isometric paper texture fixture 13,968,314 1,882,772 4,070,759 476,304
All 27 animation guide examples 7,686,084 5,323,844 481,081 333,269
947 ordinary static boards 21,643,184 21,152,350 8,224,520 7,990,466

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

- sent from alixander's Codex

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]>
@alixander
alixander merged commit 54edc4c into master Nov 24, 2026
3 checks passed
@alixander
alixander deleted the perf/reduce-svg-output branch November 24, 2026 19:43
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.

1 participant