Pure Rust port of the Eclipse Layout Kernel (ELK), engineered for 1:1 layout parity with Java ELK 0.12.2 and high-throughput execution across native Rust, Node.js (NAPI), and WebAssembly (simd128).
elk-rs ships as:
@openedges/elk-layouton npm — drop-in replacement for elkjs with automatic prebuilt native NAPI addons and WebAssembly fallback for Node.js and browsers.elk-layouton crates.io — single facade crate re-exporting all portedorg-eclipse-elk-*plugins and the elkjs-compatible JSON layout API.
- 1:1 Parity with Java ELK 0.12.2:
1,989 / 1,989comparable models match on the fullelk-modelscorpus (0drift),196,407intermediate layered processor states verified across all1,998inputs, and550 / 550Java matches across NAPI, Web WASM, and Node.js WASM. - High Performance: On Apple M1 across 26 synthetic benchmarks (
0.12.4),rust_apiaverages 5.53 ms (2.07x faster across 1,447 realworld models vs0.12.3baseline), NAPIELK.layoutaverages 5.72 ms (within 0.19 ms of raw Rust), and WASM (simd128+ ELKB v1 binary I/O) averages 9.48 ms (5.4 MB.wasmbinary) — ~12x–21x faster than Java ELK0.12.2and ~153x–263x faster thanelkjs 0.12.2. - Drop-In
elkjsAPI: Compatiblelayout(),knownLayoutAlgorithms(),knownLayoutOptions(),knownLayoutCategories(), Web Worker, and Node.jsworker_threadssupport with no GWT runtime overhead. - Cross-Platform Delivery: Prebuilt native NAPI binaries for 6 platforms (macOS, Linux glibc/musl, Windows) with transparent WASM fallback for browsers and other targets.
- Full Algorithm Coverage: Layered, Stress, Force, MrTree, Radial, DisCo, Rect Packing, SPOrE (Overlap & Compaction), Top-down Packing, VertiFlex, Box, Fixed, and Random.
npm install @openedges/elk-layout- Node.js: Requires Node.js 18 or later. On supported platforms, npm installs the matching native NAPI addon via
optionalDependencies; other targets automatically fall back to the bundled Node.js WASM module. - Browsers: Uses the bundled ESM WebAssembly module (
simd128enabled; requires Chrome 96+, Firefox 89+, or Safari 16.4+).
import ELK from '@openedges/elk-layout';
const elk = new ELK();
const graph = {
id: 'root',
layoutOptions: { 'elk.algorithm': 'layered' },
children: [
{ id: 'n1', width: 30, height: 30 },
{ id: 'n2', width: 30, height: 30 },
],
edges: [{ id: 'e1', sources: ['n1'], targets: ['n2'] }],
};
const laidOut = await elk.layout(graph);const ELK = require('@openedges/elk-layout');
const elk = new ELK();
elk.layout({
id: 'root',
layoutOptions: { 'elk.algorithm': 'layered' },
children: [
{ id: 'n1', width: 30, height: 30 },
{ id: 'n2', width: 30, height: 30 },
],
edges: [{ id: 'e1', sources: ['n1'], targets: ['n2'] }],
}).then(console.log);const ELK = require('@openedges/elk-layout');
const elk = new ELK({
workerUrl: require.resolve('@openedges/elk-layout/js/elk-worker.js'),
});
elk.layout(graph).finally(() => elk.terminateWorker());| Platform | Optional Package |
|---|---|
| macOS ARM64 (Apple Silicon) | @openedges/elk-layout-darwin-arm64 |
| macOS x64 (Intel) | @openedges/elk-layout-darwin-x64 |
| Linux x64 (glibc) | @openedges/elk-layout-linux-x64-gnu |
| Linux x64 (musl / Alpine) | @openedges/elk-layout-linux-x64-musl |
| Linux ARM64 (glibc) | @openedges/elk-layout-linux-arm64-gnu |
| Windows x64 (MSVC) | @openedges/elk-layout-win32-x64-msvc |
See plugins/org.eclipse.elk.js/README.md for the full JS/TS API reference and browser/worker details.
cargo add elk-layoutlet graph = r#"{
"id": "root",
"layoutOptions": { "elk.algorithm": "layered" },
"children": [
{ "id": "n1", "width": 30, "height": 30 },
{ "id": "n2", "width": 30, "height": 30 }
],
"edges": [{ "id": "e1", "sources": ["n1"], "targets": ["n2"] }]
}"#;
// Second argument supplies global default layout options as JSON.
let laid_out: String = elk_layout::layout_json(graph, "{}")?;When you already hold a serde_json::Value, use layout_value to avoid a JSON text round trip:
let graph_value: serde_json::Value = serde_json::from_str(graph)?;
let laid_out_value = elk_layout::layout_value(graph_value, "{}")?;All underlying ELK plugins (org-eclipse-elk-graph, org-eclipse-elk-core, org-eclipse-elk-alg-*, org-eclipse-elk-graph-json, org-eclipse-elk-conn-gmf) are also published individually at the same version with exact intra-workspace pins and re-exported under elk_layout::graph, elk_layout::core, elk_layout::alg::*, and elk_layout::graph_json. See crates/elk-layout/README.md.
| Algorithm | ELK ID |
|---|---|
| Layered | org.eclipse.elk.layered |
| Stress | org.eclipse.elk.stress |
| Force | org.eclipse.elk.force |
| MrTree | org.eclipse.elk.mrtree |
| Radial | org.eclipse.elk.radial |
| DisCo | org.eclipse.elk.disco |
| Rect Packing | org.eclipse.elk.rectpacking |
| SPOrE Overlap | org.eclipse.elk.sporeOverlap |
| SPOrE Compaction | org.eclipse.elk.sporeCompaction |
| Top-down Packing | org.eclipse.elk.topdownpacking |
| VertiFlex | org.eclipse.elk.vertiflex |
| Box / Fixed / Random | org.eclipse.elk.box, org.eclipse.elk.fixed, org.eclipse.elk.random |
Measured on a single machine (Mac mini Macmini9,1, Apple M1 8-core 4P+4E, 8 GB RAM, macOS 27.2, Rust 1.97.1, Node.js 24) using alternating A/B medians across 26 synthetic scenarios (10 iterations, 3 warmups, 5 rounds) and the 1,447-model realworld corpus (3 rounds):
| Benchmark / Engine | Baseline | 0.12.4 |
Speedup |
|---|---|---|---|
1,447 realworld models total (rust_api, vs 0.12.3 c7279b48) |
2,183.57 ms | 1,052.68 ms | 2.07x (-51.8%) |
26 synthetic mean — rust_native (mimalloc-alloc, vs c7279b48) |
7.69 ms | 5.89 ms | 1.31x (-23.4%, 26/26) |
26 synthetic mean — rust_api (layout_json, vs c7279b48) |
7.14 ms | 5.53 ms | 1.29x (-22.6%, 26/26) |
26 synthetic mean — NAPI ELK.layout (darwin-arm64, vs Phase 3 dist_p3) |
7.24 ms | 5.72 ms | 1.27x (-21.0%, 26/26) |
26 synthetic mean — WASM ELK.layout (simd128 + ELKB v1, vs dist_p3) |
12.13 ms | 9.48 ms | 1.28x (-21.8%, 24/26) |
Selected 0.12.4 synthetic scenarios (ms, lower is faster; same-machine Java ELK 0.12.2 reference from tests/upgrade_0_12_2.md):
| Scenario | rust_api (0.12.4) |
NAPI ELK.layout |
WASM ELK.layout |
Java ELK 0.12.2 (ref) |
|---|---|---|---|---|
layered_medium |
0.75 | 0.89 | 3.74 | 11.40 |
layered_xlarge |
54.16 | 54.77 | 96.72 | 457.77 |
force_xlarge |
28.79 | 30.74 | 37.70 | 1,059.44 |
stress_xlarge |
38.97 | 38.83 | 51.78 | 1,122.14 |
radial_xlarge |
1.02 | 1.23 | 4.08 | 17.41 |
mrtree_xlarge |
1.51 | 1.79 | 5.38 | 31.81 |
rectpacking_xlarge |
0.64 | 0.95 | 1.77 | 7.99 |
Full 9-phase methodology, alternating A/B tables, and verification records are published in tests/optimization_0_13_0.md and tests/upgrade_0_12_2.md.
Each release is validated against pinned upstream references (external/elk v0.12.2, external/elkjs 0.12.2, external/elk-models):
- Model Parity:
1,989 / 1,989comparable models match Java ELKv0.12.2(0drift,0errors). - Strict Phase-Step Trace:
196,407intermediate layered processor states match across all1,998corpus inputs (1,997layouts +1matchingUnsupportedGraphException). - 3-Way JS Parity:
550 / 550Java matches on NAPI, browser ESM WASM, and Node.js CJS WASM (547 PASS+3 ELKJS_DRIFT,0failures). - Workspace & JS Tests:
1,224Rust tests +70Vitest tests (0failures), plus recursive 60 ms runtime budget8 / 8(max0.71 ms). - Memory & Lifetime Regression:
1,998 / 1,998full-corpus releasememory_allocationspass with0retained bytes and0retained allocations (including exception unwind paths), plus0bytes steady-state WASM heap growth across 60 consecutive layouts.
See tests/optimization_0_13_0.md, tests/upgrade_0_12_2.md, and CHANGELOG.md for the complete 0.12.4 verification report and release notes.
- Rust
1.97.1(rust-toolchain.toml/mise.toml), withwasm32-unknown-unknowntarget for WASM builds - Node.js
24(mise.toml) for JS tests and NAPI/WASM packaging - wasm-pack and @napi-rs/cli (for building the npm package locally)
- Full parity runs against Java ELK require JDK 21 and Maven (see
TESTING.md§ 1)
git submodule update --init --recursive
cargo build --workspace
cargo clippy --workspace --all-targets
cargo test --workspacecd plugins/org.eclipse.elk.js
sh build.sh # Browser ESM WASM + Node.js CJS WASM + local NAPI addon
npm install --ignore-scripts
npm testcrates/elk-layout/: crates.io facade crate re-exporting all plugins and JSON APIsplugins/org.eclipse.elk.*: 1:1 Rust ports of ELK plugins, plusorg.eclipse.elk.napi,org.eclipse.elk.wasm, andorg.eclipse.elk.jsscripts/: build, parity, benchmark, and release automation scriptstests/: parity reports, validation docs, and benchmarksexternal/: pinned upstream submodules (elk,elkjs,elk-models) — read-only reference trees; do not modify files underexternal/
| Document | Purpose |
|---|---|
CHANGELOG.md |
User-facing release history |
VERSIONING.md |
Versioning, branching, submodule pinning, and publishing policy |
TESTING.md |
Environment setup, verification gates, and release checklist |
tests/optimization_0_13_0.md |
0.12.4 9-phase optimization benchmarks and verification gates |
tests/upgrade_0_12_2.md |
0.12.3 (ELK 0.12.2) porting, parity, and performance report |
tests/PARITY.md |
Parity verification architecture and rules |
Eclipse Public License 2.0 (EPL-2.0 OR GPL-3.0-or-later). This Source Code may also be made available under GPL-3.0-or-later when the conditions for secondary licensing set forth in EPL-2.0 are satisfied, matching Java ELK 0.12.2. See LICENSE and NOTICE.