Skip to content

Compact compiled machine runtime - #60

Merged
SandroMaglione merged 1 commit into
mainfrom
codex/unified-machine-system
Aug 9, 2026
Merged

Compact compiled machine runtime#60
SandroMaglione merged 1 commit into
mainfrom
codex/unified-machine-system

Conversation

@SandroMaglione

@SandroMaglione SandroMaglione commented Aug 9, 2026

Copy link
Copy Markdown
Member

Summary

  • replace the closure-heavy compiled statechart runtime with a compact class-backed process kernel whose operations are shared through the prototype
  • materialize terminal waiting and snapshot-observation primitives only when those public capabilities are used, while leaving arbitrary Machine.logic processes on the general runtime
  • preserve independent actor scheduling, child cleanup, terminal arbitration, and interruption semantics, with regression coverage for stopping a blocked compiled drain

Changeset

  • Added or updated for a library or package-metadata change
  • Not required because this PR does not change src/ or package.json

Validation

  • pnpm check
  • Relevant example checks, when examples changed
  • Reviewed the automated type-performance report, when the public TypeScript API or inference changed
  • Reviewed the automated runtime-performance report, when runtime behavior changed

The public API and type inference are unchanged. Local validation also included pnpm perf:types, three process-isolated base/candidate benchmark pairs, and matching full-duration runtime reports. The five-process CI comparison confirms the retained-memory reduction and positive runtime direction.

@github-actions

github-actions Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Type performance

Measured with TypeScript 6.0.3 and skipLibCheck=true.

Scenario Base PR Difference
Effect only 55 55 0 (0.0%)
Import effect-machine 55 55 0 (0.0%)
Machine.defineStates (3 states) 2,965 2,965 0 (0.0%)
Machine.make (3 states, 2 events) 8,715 8,715 0 (0.0%)
machine.handle (3 states, 2 transitions) 23,492 23,492 0 (0.0%)
machine.handle (depth 8) 117,075 117,075 0 (0.0%)
machine.handle (depth 12) 129,713 129,713 0 (0.0%)
machine.handle (depth 16) 145,055 145,055 0 (0.0%)
machine.handle (depth 24) 183,851 183,851 0 (0.0%)
machine.handle (wide depth 16) 214,189 214,189 0 (0.0%)
machine.handle (parallel/history/choice) 132,667 132,667 0 (0.0%)
machine.handle (4 successive calls) 128,674 128,674 0 (0.0%)
machine exact input/output/error/services 110,584 110,584 0 (0.0%)
execution adapter readiness 127,854 127,854 0 (0.0%)

Marginal instantiations are measured against the matching setup without that API call:

Scenario Base PR Difference
Import effect-machine 0 0 0
Machine.defineStates (3 states) 2,910 2,910 0 (0.0%)
Machine.make (3 states, 2 events) 5,742 5,742 0 (0.0%)
machine.handle (3 states, 2 transitions) 14,777 14,777 0 (0.0%)
machine.handle (depth 8) 109,601 109,601 0 (0.0%)
machine.handle (depth 12) 121,039 121,039 0 (0.0%)
machine.handle (depth 16) 135,181 135,181 0 (0.0%)
machine.handle (depth 24) 171,577 171,577 0 (0.0%)
machine.handle (wide depth 16) 202,224 202,224 0 (0.0%)
machine.handle (parallel/history/choice) 114,331 114,331 0 (0.0%)
machine.handle (4 successive calls) 113,703 113,703 0 (0.0%)
machine exact input/output/error/services 100,670 100,670 0 (0.0%)
execution adapter readiness 102,092 102,092 0 (0.0%)
Check times (informational)
Scenario Base PR
Effect only 0.03s 0.03s
Import effect-machine 0.03s 0.03s
Machine.defineStates (3 states) 0.09s 0.09s
Machine.make (3 states, 2 events) 0.15s 0.15s
machine.handle (3 states, 2 transitions) 0.21s 0.22s
machine.handle (depth 8) 0.48s 0.48s
machine.handle (depth 12) 0.52s 0.52s
machine.handle (depth 16) 0.56s 0.55s
machine.handle (depth 24) 0.62s 0.62s
machine.handle (wide depth 16) 0.70s 0.68s
machine.handle (parallel/history/choice) 0.58s 0.57s
machine.handle (4 successive calls) 0.54s 0.53s
machine exact input/output/error/services 0.46s 0.47s
execution adapter readiness 0.54s 0.53s

Type instantiations are the comparison metric. Check time varies with runner load and is informational only.

@github-actions

github-actions Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Runtime performance

Median of 5 independent benchmark processes on AMD EPYC 7763 64-Core Processor with Node v24.18.0.

Pull request baseline

Scenario Effect Machine XState 5 XState 6 alpha
Plan counter transitions 101,637 transitions/s 112,360 transitions/s 125,551 transitions/s
Drain burst with terminal fence 92,931 increments/s 414,195 increments/s 113,676 increments/s
Drain burst with a change observer 67,451 increments/s 411,008 increments/s 113,599 increments/s
Lookup and send to one child 86,465 increments/s 408,432 increments/s 108,929 increments/s
Start and stop a machine 21,841 machines/s 190,150 machines/s 74,543 machines/s
Start and stop a parent with one child 8,553 families/s 71,144 families/s 26,977 families/s

Effect runtime reference points

Scenario Effect Machine Effect runtime primitives
Start and stop a raw compiled process 35,343 processes/s
Start and interrupt a suspended fiber 169,176 fibers/s
Start and stop a queue worker 117,288 workers/s
Start and stop an actor shell 109,206 actors/s
Start and stop two actor shells 67,668 families/s
Update an owner-only mutable snapshot 317,863,954 updates/s
Update a synchronized snapshot 1,556,510 updates/s
Create, resolve, and await a terminal latch 1,471,642 latches/s
Memory profile Effect Machine XState 5 XState 6 alpha Effect runtime primitives
Idle machine 2.2 KiB 3.8 KiB 6.1 KiB
Raw generic managed process 12.3 KiB
Raw compiled process 2.7 KiB
Two independent idle machines 4.0 KiB 7.3 KiB 11.8 KiB
Idle parent with one child 6.3 KiB 5.5 KiB 8.8 KiB
Parent with observed child registry 10.5 KiB
Parent with observed invoked child snapshots 6.5 KiB
Suspended Effect fiber 0.7 KiB
Effect queue with waiting fiber 2.8 KiB
Effect mailbox actor shell 3.2 KiB
Two Effect actor shells 6.9 KiB

Effect Machine change from base

Metric Base Base variability PR PR variability Difference
Plan counter transitions 101,668 transitions/s 1.7% MAD 101,637 transitions/s 5.1% MAD -0.0%
Drain burst with terminal fence 90,271 increments/s 3.1% MAD 92,931 increments/s 3.9% MAD +2.9%
Drain burst with a change observer 66,056 increments/s 1.0% MAD 67,451 increments/s 5.1% MAD +2.1%
Lookup and send to one child 83,630 increments/s 4.0% MAD 86,465 increments/s 3.8% MAD +3.4%
Start and stop a machine 20,246 machines/s 1.4% MAD 21,841 machines/s 2.2% MAD +7.9%
Start and stop a parent with one child 7,675 families/s 2.4% MAD 8,553 families/s 4.4% MAD +11.4%
Idle machine heap per unit 7.0 KiB 0.0% MAD 2.2 KiB 0.0% MAD -67.8%
Raw generic managed process heap per unit 12.3 KiB 0.1% MAD 12.3 KiB 0.0% MAD +0.1%
Raw compiled process heap per unit 7.6 KiB 0.1% MAD 2.7 KiB 0.1% MAD -64.3%
Two independent idle machines heap per unit 13.5 KiB 0.0% MAD 4.0 KiB 0.0% MAD -69.9%
Idle parent with one child heap per unit 15.8 KiB 0.0% MAD 6.3 KiB 0.0% MAD -60.0%
Parent with observed child registry heap per unit 19.9 KiB 0.0% MAD 10.5 KiB 0.0% MAD -47.4%
Parent with observed invoked child snapshots heap per unit 15.9 KiB 0.0% MAD 6.5 KiB 0.0% MAD -59.4%

Effect runtime reference change from base

Metric Base Base variability PR PR variability Difference
Start and stop a raw compiled process 31,477 processes/s 0.8% MAD 35,343 processes/s 1.1% MAD +12.3%
Start and interrupt a suspended fiber 168,890 fibers/s 0.0% MAD 169,176 fibers/s 0.5% MAD +0.2%
Start and stop a queue worker 115,794 workers/s 1.7% MAD 117,288 workers/s 1.4% MAD +1.3%
Start and stop an actor shell 107,910 actors/s 1.2% MAD 109,206 actors/s 1.1% MAD +1.2%
Start and stop two actor shells 65,794 families/s 2.4% MAD 67,668 families/s 0.9% MAD +2.8%
Update an owner-only mutable snapshot 316,856,781 updates/s 0.0% MAD 317,863,954 updates/s 0.0% MAD +0.3%
Update a synchronized snapshot 1,505,197 updates/s 0.7% MAD 1,556,510 updates/s 1.3% MAD +3.4%
Create, resolve, and await a terminal latch 1,443,593 latches/s 2.2% MAD 1,471,642 latches/s 1.5% MAD +1.9%
Versions and interpretation
  • Effect Machine: 0.3.0
  • XState 5: 5.32.5
  • XState 6 alpha: 6.0.0-alpha.27
  • Effect runtime primitives: 4.0.0-beta.105

Higher throughput is better; lower heap is better. Variability is the median absolute deviation across independent processes, relative to their median. Runtime measurements on shared GitHub-hosted hardware remain informational, so small differences should be confirmed across multiple workflow runs.

@SandroMaglione
SandroMaglione merged commit fc9989b into main Aug 9, 2026
9 checks passed
@SandroMaglione
SandroMaglione deleted the codex/unified-machine-system branch August 9, 2026 11:25
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