Skip to content

Add wasm-based elkjs version using teavm transpilation#376

Draft
uruuru wants to merge 11 commits intomasterfrom
uru/teavmWasm
Draft

Add wasm-based elkjs version using teavm transpilation#376
uruuru wants to merge 11 commits intomasterfrom
uru/teavmWasm

Conversation

@uruuru
Copy link
Copy Markdown
Member

@uruuru uruuru commented Apr 10, 2026

Seeing #372 the other day made me curious what has changed during the last ~8 years regarding transpilation options (also see #103). So I gave teavm a try, and it seems to work with a couple of fixes outlined below.

The package structure, public API, and publishing process likely still need some adjustment before this lands. I didn't really follow what people require nowadays for properly integrating elkjs in their projects.

Results

All 550 eclipse-elk/elk-models json files produce equivalent layout results for elk, elkjs-gwt, and elkjs-wasm (after applying the ELK fix mentioned below).

Speedup of wasm vs gwt seems to be ~3 for my machine and the benchmark setup: slightly higher for smaller models, slightly lower for larger ones.

image image

Required fixes

  • There are a couple if issues in teavm's jdk emulation:
    • TLinkedList does not implement Cloneable, preventing ElkReflect from properly creating default (mutable) layout option values for KVectorChains, e.g. (I don't know if the omission of Cloneable is on purpose, though),
    • TAbstractList's TListIterator behaved incorrectly. ELK uses iterators frequently to modify lists during iteration (e.g. during crossing minimization).
    • TRandom wasn't sufficiently deterministic when seeded, making results non-deterministic and impossible to compare for equivalence to elk
  • There's one non-determinism in elk itself

The teavm points are worked around here by recreating the relevant package locally for the build process. However, it may be worthwhile to address them upstream instead. Either way, great work by teavm!

Further additions

  • execute mocha tests for both elkjs flavors (splitting the test files into common and gwt/wasm specific ones)
  • add a dedicated test to check usage in a react/vite project
  • add a script to run elk, elkjs-gwt, and elkjs-wasm for the same graph, comparing layout results for equality

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant