Skip to content

Optimize child process ownership - #43

Merged
SandroMaglione merged 2 commits into
mainfrom
codex/compact-child-ownership
Aug 8, 2026
Merged

Optimize child process ownership#43
SandroMaglione merged 2 commits into
mainfrom
codex/compact-child-ownership

Conversation

@SandroMaglione

Copy link
Copy Markdown
Member

Summary

  • consolidate child supervision and registry state into one compact owner
  • track anonymous children directly instead of retaining per-child scope finalizers
  • allocate child observation resources only when consumed while preserving ordered replay
  • cover named/anonymous cleanup, initialization-stop races, and first-observation races

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 (not applicable)
  • Reviewed the automated type-performance report, when the public TypeScript API or inference changed (public API unchanged; local budget passes)
  • Reviewed the automated runtime-performance report, when runtime behavior changed

@github-actions

github-actions Bot commented Aug 8, 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.11s 0.11s
Machine.make (3 states, 2 events) 0.17s 0.16s
machine.handle (3 states, 2 transitions) 0.24s 0.23s
machine.handle (depth 8) 0.51s 0.53s
machine.handle (depth 12) 0.58s 0.59s
machine.handle (depth 16) 0.60s 0.63s
machine.handle (depth 24) 0.69s 0.71s
machine.handle (wide depth 16) 0.77s 0.80s
machine.handle (parallel/history/choice) 0.64s 0.66s
machine.handle (4 successive calls) 0.61s 0.62s
machine exact input/output/error/services 0.53s 0.53s
execution adapter readiness 0.57s 0.59s

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

@github-actions

github-actions Bot commented Aug 8, 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 106,515 transitions/s 133,449 transitions/s 123,030 transitions/s
Drain burst with terminal fence 55,656 increments/s 401,210 increments/s 112,550 increments/s
Drain burst with a change observer 43,793 increments/s 398,436 increments/s 112,218 increments/s
Lookup and send to one child 51,560 increments/s 395,455 increments/s 107,534 increments/s
Start and stop a machine 10,850 machines/s 184,128 machines/s 73,448 machines/s
Start and stop a parent with one child 4,102 families/s 68,644 families/s 26,969 families/s
Memory profile Effect Machine XState 5 XState 6 alpha Effect runtime primitives
Idle machine 17.8 KiB 3.8 KiB 6.1 KiB
Raw managed process 13.1 KiB
Two independent idle machines 34.8 KiB 7.3 KiB 11.8 KiB
Idle parent with one child 58.5 KiB 5.5 KiB 8.8 KiB
Parent with observed child registry 69.7 KiB
Suspended Effect fiber 0.6 KiB
Effect queue with waiting fiber 2.8 KiB
Effect mailbox actor shell 3.2 KiB

Effect Machine change from base

Metric Base Base variability PR PR variability Difference
Plan counter transitions 107,136 transitions/s 2.5% MAD 106,515 transitions/s 0.7% MAD -0.6%
Drain burst with terminal fence 54,216 increments/s 1.1% MAD 55,656 increments/s 1.0% MAD +2.7%
Drain burst with a change observer 43,116 increments/s 2.1% MAD 43,793 increments/s 0.6% MAD +1.6%
Lookup and send to one child 49,773 increments/s 1.5% MAD 51,560 increments/s 0.6% MAD +3.6%
Start and stop a machine 10,866 machines/s 0.8% MAD 10,850 machines/s 1.1% MAD -0.1%
Start and stop a parent with one child 3,797 families/s 0.7% MAD 4,102 families/s 0.8% MAD +8.0%
Idle machine heap per unit 18.0 KiB 0.0% MAD 17.8 KiB 0.0% MAD -1.2%
Raw managed process heap per unit 13.3 KiB 0.0% MAD 13.1 KiB 0.0% MAD -1.5%
Two independent idle machines heap per unit 35.3 KiB 0.0% MAD 34.8 KiB 0.0% MAD -1.2%
Idle parent with one child heap per unit 63.7 KiB 0.0% MAD 58.5 KiB 0.0% MAD -8.1%
Parent with observed child registry heap per unit 72.5 KiB 0.0% MAD 69.7 KiB 0.0% MAD -3.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 73c1e6d into main Aug 8, 2026
9 checks passed
@SandroMaglione
SandroMaglione deleted the codex/compact-child-ownership branch August 8, 2026 13:41
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