Skip to content

Build D2 WebAssembly with TinyGo - #2966

Merged
alixander merged 4 commits into
masterfrom
alixander/tinygo-wasm
Nov 19, 2026
Merged

alixander merged 4 commits into
masterfrom
alixander/tinygo-wasm

Conversation

@alixander

@alixander alixander commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

Human


AI

Build the browser and Node D2.js packages with TinyGo 0.44.0. With the Safari fix on base 8e054d14, the standard Go release build (Binaryen 131, wasm-opt -O2) produces a 55.95 MiB module. TinyGo produces 23.76 MiB. The Brotli payload embedded in the browser bundle falls from 10.69 to 6.43 MiB (39.8%).

  • Use TinyGo for local builds, CI, npm release staging, and the WASM package tests. Bundle its matching JavaScript runtime for browsers, CommonJS, and ESM. CI verifies the TinyGo and Binaryen downloads. Staging an older release tag still uses its original compiler and optimizer.
  • Set a 1 MiB goroutine stack for D2 initialization. Keep browser imports on the in-memory filesystem and use bundled fonts. Return an error for rooted filesystem access or public-only network requests when the host cannot enforce those policies.
  • Pin the typed Dagre node-label change in Use a typed node-label callback for Dagre layer graphs dagro#5. Keep the isometric route hash unsigned so it can index the palette on wasm32.

Verification

  • Ten diagrams produced byte-identical SVG and diagram JSON with both compilers, covering Dagre, ELK, TALA, Markdown, LaTeX, code, sketch, and isometric rendering.
  • Both Go WASM test packages passed under TinyGo, along with the native tests for the affected packages, TypeScript checks, 52 D2.js unit tests, and all 10 installed-package tests. Both npm names compiled and rendered in fresh CommonJS and ESM consumers.
  • The branch includes the Safari worker fix from Fix d2.js startup in Safari workers with Goldmark v2 #2965. Chrome and macOS 27.2.1 system WebKit both rendered with Dagre, ELK, and TALA, rendered an isometric diagram, and reused the worker after a syntax error. WebKit also rendered a Markdown table with strikethrough.

In the comparison against base 7d483240, the full Linux CI job passed in 24m 43s on this PR and 12m 04s on the base. PR run · Base run

  • sent from alixander's Codex

@alixander
alixander merged commit 2837ac1 into master Nov 19, 2026
15 checks passed
@alixander
alixander deleted the alixander/tinygo-wasm branch November 19, 2026 17:18
alixander added a commit that referenced this pull request Nov 26, 2026
d2js/js/README.md: put back the Development paragraph naming TinyGo
0.44.0-d2.2 from d2lang/tinygo. Resolving the isometric conflict with
master's whole file had dropped it, and the build refuses stock TinyGo.

Changelogs: sizes and speed against master 40e942d, whose module lost
4.5 MB with isometric rendering. The module is a further 49.7% smaller
(32.6% with Brotli) and takes 55% of the time. next.md gains an entry for
the TinyGo switch (#2966) these numbers build on, states the asyncify
growth for the code as a whole, as ci/wasm-flags.sh does, and limits the
shared sort routine to D2's own sorts.

CI: test TALA's scheduler.none variants natively. ci/wasm-flags.sh,
ci/wasm-goroutines.txt and *_nosched.go now select the wasm job and
ci/wasm-strip the packed browser job; the first three and ci/wasm-strip
selected no job before.

THIRD_PARTY_NOTICES.txt: the TinyGo runtime and wasm_exec.js in the
module come from d2lang/tinygo v0.44.0-d2.2.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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