Skip to content

d2elk: replace embedded ELK.js with native elk-go - #2820

Merged
alixander merged 2 commits into
masterfrom
agent/use-elk-go
Aug 9, 2026
Merged

alixander merged 2 commits into
masterfrom
agent/use-elk-go

Conversation

@alixander

@alixander alixander commented Aug 9, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • replace the embedded ELK.js 0.8.2 / Goja execution path with the native Go port in d2lang/elk-go#1
  • use the same Go layout path in native builds and WASM
  • remove the 3.7 MB ELK JavaScript bundle, setup script, embed shims, browser loader, and worker injection
  • retain the existing D2 graph preparation and route post-processing
  • add regression coverage for all 12 ELK algorithms exposed by --elk-algorithm
  • ship complete EPL-2.0, ELK NOTICE, and Apache-2.0 attribution in source, release archives, npm packages, MSI, and Docker paths

Output compatibility

The port targets the exact ELK.js 0.8.2 behavior previously embedded by D2.

  • extracted D2 ELK corpus: 322/322 pass
  • full TestE2E: pass
  • the sole raw board delta is two occurrences of 93.4990005493164 becoming 93.5 (about 0.001 px)
  • the corresponding SVG is byte-identical after normalizing that coordinate and the derived document hash

Screenshots are not useful for this autolayout change because the output is visually identical at that sub-pixel delta.

JavaScript removal

There is no runtime ELK JavaScript, ELK loader, ELK setup script, ELK Goja call, or embedded ELK asset in this path anymore. D2 still uses Goja elsewhere for unrelated LaTeX/sketch rendering.

The only JavaScript in the elk-go repository is an opt-in test oracle used to compare the Go implementation with the pinned ELK.js bundle.

Validation

All commands below were run with the real pushed elk-go pseudo-version and GOWORK=off:

  • go test ./d2layouts/d2elklayout
  • go vet ./d2layouts/d2elklayout ./d2plugin
  • GOOS=js GOARCH=wasm go build ./d2js
  • go test ./e2etests -run TestE2E -count=1
  • browser, Node ESM, and Node CJS package builds
  • 32 D2.js unit tests and 2 Node integration tests
  • real Node/WASM compile("x -> y", {layout: "elk"}) smoke test

A repository-wide local go test ./... passes all packages except the same two GIF CLI conversion cases that fail on the untouched baseline in this environment.

Size impact

Moving the runtime into Go increases the raw WASM binary by 22.1% and its Brotli output by 16.3%. The packed npm artifacts grow about 9.1%; native CLI binaries grow 0.8–1.3%. The separate ELK JavaScript/runtime assets are removed.

Merge sequencing

d2lang/elk-go#1 is merged and published as v0.1.0. This PR pins that released version with no local replace.

@alixander
alixander marked this pull request as ready for review August 9, 2026 04:49
@alixander
alixander merged commit 87f6900 into master Aug 9, 2026
6 checks passed
@alixander
alixander deleted the agent/use-elk-go branch August 9, 2026 04:54
@pancsta

pancsta commented Aug 9, 2026

Copy link
Copy Markdown

Great stuff, does this mean the rendering speed of ELK will increase? In my case it’s sometimes around 60sec for a single SVG…

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.

2 participants