Skip to content

Add ClusterMachine shardGroup, Entity.toLayer options, and transactional onCommit - #315

Merged
SandroMaglione merged 1 commit into
mainfrom
cluster-machine-entity-options
Nov 25, 2026
Merged

SandroMaglione merged 1 commit into
mainfrom
cluster-machine-entity-options

Conversation

@SandroMaglione

Copy link
Copy Markdown
Member

Summary

  • Add optional shardGroup?: (entityId: EntityId) => string to ClusterMachine.make options, annotating both the entity and any invoked child entities with ClusterSchema.ShardGroup (mapping child entity IDs back to their parent's shard group).
  • Export LayerOptions<M, RE, RC> and CommitEvent<M> on ClusterMachine, forwarding Effect Cluster's standard Entity.toLayer tuning options (maxIdleTime, concurrency, mailboxCapacity, mailboxMetrics, disableFatalDefects, defectRetryPolicy, spanAttributes) to the entity and its children.
  • Add transactional onCommit to LayerOptions, invoked inside the same MessageStorage transaction immediately after every committed checkpoint (active, done, or failed) with { entityId, checkpoint, snapshot }, rolling back atomically with the checkpoint on failure (rejecting request steps as PersistenceFailure and retrying background invocation/timer steps).
  • Add SQLite + PostgreSQL transactional rollback tests, shard-group and maxIdleTime passivation tests, type tests, documentation updates, and a minor changeset.

Changeset

  • Added or updated for a library or package-metadata change
  • Not required because this PR does not change a publishable package

Validation

  • pnpm check
  • Automated type-performance measurement passed or was not required
  • Automated runtime- and memory-performance measurement passed or was not required

@github-actions

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.state (3 children) 2,396 2,396 0 (0.0%)
Machine.make (3 states, 2 events) 8,573 8,573 0 (0.0%)
machine.handle (3 states, 2 transitions) 45,085 45,085 0 (0.0%)
declared transition (10 named branches) 71,452 71,452 0 (0.0%)
atomic construction, guards, and reentry 83,762 83,762 0 (0.0%)
registered invocation (input-taking Effect) 41,264 41,264 0 (0.0%)
registered invocations (Stream, Logic, child) 89,562 89,562 0 (0.0%)
machine.handle (depth 24) 191,846 191,846 0 (0.0%)
machine.handle (wide depth 16) 215,905 215,905 0 (0.0%)
machine.handle (parallel/history/choice) 106,289 106,289 0 (0.0%)
machine definition (3 independent implementations) 97,653 97,653 0 (0.0%)
machine exact input/output/error/services 86,092 86,092 0 (0.0%)
execution adapter readiness 75,034 75,095 +61 (+0.1%)

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

Scenario Base PR Difference
Import effect-machine 0 0 0
Machine.state (3 children) 2,341 2,341 0 (0.0%)
Machine.make (3 states, 2 events) 6,169 6,169 0 (0.0%)
machine.handle (3 states, 2 transitions) 36,512 36,512 0 (0.0%)
declared transition (10 named branches) 63,258 63,258 0 (0.0%)
atomic construction, guards, and reentry 68,807 68,807 0 (0.0%)
registered invocation (input-taking Effect) 34,454 34,454 0 (0.0%)
registered invocations (Stream, Logic, child) 53,504 53,504 0 (0.0%)
machine.handle (depth 24) 176,165 176,165 0 (0.0%)
machine.handle (wide depth 16) 201,170 201,170 0 (0.0%)
machine.handle (parallel/history/choice) 94,523 94,523 0 (0.0%)
machine definition (3 independent implementations) 87,449 87,449 0 (0.0%)
machine exact input/output/error/services 74,268 74,268 0 (0.0%)
execution adapter readiness 26,894 26,955 +61 (+0.2%)
Check times (informational)
Scenario Base PR
Effect only 0.03s 0.03s
Import effect-machine 0.03s 0.03s
Machine.state (3 children) 0.09s 0.10s
Machine.make (3 states, 2 events) 0.16s 0.17s
machine.handle (3 states, 2 transitions) 0.32s 0.35s
declared transition (10 named branches) 0.45s 0.49s
atomic construction, guards, and reentry 0.53s 0.59s
registered invocation (input-taking Effect) 0.32s 0.34s
registered invocations (Stream, Logic, child) 0.58s 0.62s
machine.handle (depth 24) 0.63s 0.66s
machine.handle (wide depth 16) 0.70s 0.72s
machine.handle (parallel/history/choice) 0.59s 0.62s
machine definition (3 independent implementations) 0.53s 0.59s
machine exact input/output/error/services 0.55s 0.59s
execution adapter readiness 0.47s 0.49s

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

@github-actions

Copy link
Copy Markdown
Contributor

Runtime performance

Median of 5 independent benchmark processes on Intel(R) Xeon(R) 6973P-C with Node v24.22.3.

Pull request baseline

Scenario Effect Machine
Plan counter transitions 178,265 transitions/s
Drain burst with terminal fence 664,016 increments/s
Drain burst with a change observer 607,525 increments/s
Lookup and send to one child 537,288 increments/s
Start and stop a machine 185,529 machines/s
Start and stop a parent with one child 57,290 families/s
Complete an Effect invocation with tracing enabled 19,839 invocations/s
Complete an Effect invocation with tracing disabled 22,653 invocations/s
Plan transitions through a compound state 155,910 transitions/s
Plan transitions through parallel regions 127,073 transitions/s
Drain burst through a compound state 541,553 events/s
Drain burst through two parallel regions 492,170 events/s
Drain a compound-state burst with a change observer 508,138 events/s

Process runtime reference points

Scenario Effect Machine
Start and stop a raw generic process 61,550 processes/s
Start and stop a raw compiled process 110,779 processes/s
Memory profile Effect Machine
Idle machine 1.9 KiB
Raw generic managed process 11.4 KiB
Raw compiled process 3.2 KiB
Two independent idle machines 3.6 KiB
Idle parent with one child 6.1 KiB
Parent with observed child registry 9.7 KiB
Parent with observed invoked child snapshots 7.1 KiB

Effect Machine change from base

Metric Base Base variability PR PR variability Difference
Plan counter transitions 182,844 transitions/s 0.3% MAD 178,265 transitions/s 1.2% MAD -2.5%
Drain burst with terminal fence 678,040 increments/s 1.0% MAD 664,016 increments/s 3.0% MAD -2.1%
Drain burst with a change observer 631,785 increments/s 1.3% MAD 607,525 increments/s 3.3% MAD -3.8%
Lookup and send to one child 542,870 increments/s 1.2% MAD 537,288 increments/s 2.5% MAD -1.0%
Start and stop a machine 185,426 machines/s 0.1% MAD 185,529 machines/s 0.2% MAD +0.1%
Start and stop a parent with one child 56,596 families/s 2.7% MAD 57,290 families/s 0.9% MAD +1.2%
Complete an Effect invocation with tracing enabled 19,031 invocations/s 1.0% MAD 19,839 invocations/s 1.3% MAD +4.2%
Complete an Effect invocation with tracing disabled 23,084 invocations/s 1.1% MAD 22,653 invocations/s 2.4% MAD -1.9%
Plan transitions through a compound state 161,610 transitions/s 1.2% MAD 155,910 transitions/s 3.4% MAD -3.5%
Plan transitions through parallel regions 127,891 transitions/s 0.9% MAD 127,073 transitions/s 1.4% MAD -0.6%
Drain burst through a compound state 528,877 events/s 2.1% MAD 541,553 events/s 0.9% MAD +2.4%
Drain burst through two parallel regions 491,344 events/s 2.0% MAD 492,170 events/s 1.1% MAD +0.2%
Drain a compound-state burst with a change observer 500,484 events/s 1.7% MAD 508,138 events/s 0.4% MAD +1.5%
Idle machine heap per unit 1.9 KiB 0.7% MAD 1.9 KiB 0.8% MAD -0.8%
Raw generic managed process heap per unit 11.4 KiB 0.0% MAD 11.4 KiB 0.1% MAD -0.1%
Raw compiled process heap per unit 3.2 KiB 0.0% MAD 3.2 KiB 0.7% MAD +1.1%
Two independent idle machines heap per unit 3.6 KiB 0.1% MAD 3.6 KiB 0.1% MAD -0.1%
Idle parent with one child heap per unit 6.1 KiB 0.4% MAD 6.1 KiB 0.3% MAD -0.1%
Parent with observed child registry heap per unit 9.7 KiB 0.0% MAD 9.7 KiB 0.0% MAD +0.0%
Parent with observed invoked child snapshots heap per unit 7.1 KiB 0.0% MAD 7.1 KiB 0.0% MAD +0.2%

Process runtime reference change from base

Metric Base Base variability PR PR variability Difference
Start and stop a raw generic process 62,027 processes/s 0.9% MAD 61,550 processes/s 0.6% MAD -0.8%
Start and stop a raw compiled process 111,074 processes/s 0.8% MAD 110,779 processes/s 0.9% MAD -0.3%

Regression guard

No large, noise-adjusted throughput or heap regressions detected.

Versions and interpretation
  • Effect Machine: 0.47.1

Higher throughput is better; lower heap is better. Variability is the median absolute deviation across independent processes, relative to their median. Small differences on shared GitHub-hosted hardware remain informational; the required guard rejects only large changes beyond the measured noise allowance.

@SandroMaglione
SandroMaglione merged commit 06cbe55 into main Nov 25, 2026
9 checks passed
@SandroMaglione
SandroMaglione deleted the cluster-machine-entity-options branch November 25, 2026 06:10
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