Skip to content

Compact child observation - #57

Merged
SandroMaglione merged 1 commit into
mainfrom
codex/compact-child-observation
Aug 9, 2026
Merged

Compact child observation#57
SandroMaglione merged 1 commit into
mainfrom
codex/compact-child-observation

Conversation

@SandroMaglione

@SandroMaglione SandroMaglione commented Aug 9, 2026

Copy link
Copy Markdown
Member

Summary

  • replace the replaying child-registry PubSub and complete registry snapshots with compact, scoped observer handoffs
  • preserve initial replay, independent subscribers, registry-wide emission ticks, ordered backlog delivery, and lifecycle race safety
  • keep the unobserved representation allocation-free and release observer state when a stream is finalized
  • add coverage for multiple subscribers, compatibility ticks, and a stalled observer backlog

Why

Observing one child previously cloned and retained the complete child registry behind a replaying PubSub. The public stream only needs the selected child value, so retaining full snapshots made observation substantially more expensive than the underlying registry.

Changeset

  • Added a patch changeset for the runtime memory improvement.

Validation

  • pnpm check
  • pnpm perf:types
  • Three independent local runtime benchmark processes for both main and this branch
  • Relevant example checks are covered by pnpm check
  • Reviewed the independent CI runtime performance report

The local median reduces observed child-registry retained heap from 28.0 KiB to 21.2 KiB (-24.3%). Unobserved machine and child-family memory are unchanged within measurement precision; control throughput benchmarks show no material regression.

@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.04s 0.04s
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.27s 0.25s
machine.handle (depth 8) 0.56s 0.52s
machine.handle (depth 12) 0.59s 0.59s
machine.handle (depth 16) 0.64s 0.61s
machine.handle (depth 24) 0.73s 0.70s
machine.handle (wide depth 16) 0.81s 0.79s
machine.handle (parallel/history/choice) 0.66s 0.64s
machine.handle (4 successive calls) 0.63s 0.59s
machine exact input/output/error/services 0.53s 0.54s
execution adapter readiness 0.60s 0.60s

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 107,347 transitions/s 140,612 transitions/s 125,849 transitions/s
Drain burst with terminal fence 89,863 increments/s 413,435 increments/s 114,661 increments/s
Drain burst with a change observer 66,607 increments/s 410,990 increments/s 114,359 increments/s
Lookup and send to one child 84,908 increments/s 409,371 increments/s 109,054 increments/s
Start and stop a machine 18,776 machines/s 191,975 machines/s 73,883 machines/s
Start and stop a parent with one child 6,569 families/s 70,641 families/s 27,235 families/s

Effect runtime reference points

Scenario Effect Machine Effect runtime primitives
Start and stop a raw compiled process 30,863 processes/s
Start and interrupt a suspended fiber 168,606 fibers/s
Start and stop a queue worker 117,980 workers/s
Start and stop an actor shell 108,968 actors/s
Start and stop two actor shells 68,087 families/s
Update an owner-only mutable snapshot 316,856,781 updates/s
Update a synchronized snapshot 1,547,755 updates/s
Create, resolve, and await a terminal latch 1,438,518 latches/s
Memory profile Effect Machine XState 5 XState 6 alpha Effect runtime primitives
Idle machine 7.5 KiB 3.8 KiB 6.1 KiB
Raw generic managed process 12.5 KiB
Raw compiled process 7.8 KiB
Two independent idle machines 14.5 KiB 7.3 KiB 11.8 KiB
Idle parent with one child 17.0 KiB 5.5 KiB 8.8 KiB
Parent with observed child registry 21.2 KiB
Parent with observed invoked child snapshots 17.2 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 110,215 transitions/s 0.7% MAD 107,347 transitions/s 4.1% MAD -2.6%
Drain burst with terminal fence 91,695 increments/s 1.5% MAD 89,863 increments/s 2.1% MAD -2.0%
Drain burst with a change observer 66,678 increments/s 2.2% MAD 66,607 increments/s 0.3% MAD -0.1%
Lookup and send to one child 85,613 increments/s 0.7% MAD 84,908 increments/s 0.9% MAD -0.8%
Start and stop a machine 18,368 machines/s 0.9% MAD 18,776 machines/s 1.5% MAD +2.2%
Start and stop a parent with one child 6,519 families/s 0.4% MAD 6,569 families/s 3.1% MAD +0.8%
Idle machine heap per unit 7.5 KiB 0.0% MAD 7.5 KiB 0.0% MAD 0.0%
Raw generic managed process heap per unit 12.5 KiB 0.0% MAD 12.5 KiB 0.0% MAD -0.0%
Raw compiled process heap per unit 7.8 KiB 0.3% MAD 7.8 KiB 0.2% MAD -0.0%
Two independent idle machines heap per unit 14.5 KiB 0.0% MAD 14.5 KiB 0.0% MAD 0.0%
Idle parent with one child heap per unit 17.0 KiB 0.0% MAD 17.0 KiB 0.0% MAD -0.0%
Parent with observed child registry heap per unit 28.0 KiB 0.0% MAD 21.2 KiB 0.0% MAD -24.3%
Parent with observed invoked child snapshots heap per unit 17.2 KiB 0.0% MAD 17.2 KiB 0.0% MAD -0.0%

Effect runtime reference change from base

Metric Base Base variability PR PR variability Difference
Start and stop a raw compiled process 31,378 processes/s 0.2% MAD 30,863 processes/s 0.6% MAD -1.6%
Start and interrupt a suspended fiber 169,463 fibers/s 0.5% MAD 168,606 fibers/s 0.3% MAD -0.5%
Start and stop a queue worker 118,120 workers/s 1.3% MAD 117,980 workers/s 0.6% MAD -0.1%
Start and stop an actor shell 109,087 actors/s 2.1% MAD 108,968 actors/s 0.3% MAD -0.1%
Start and stop two actor shells 66,765 families/s 4.4% MAD 68,087 families/s 1.3% MAD +2.0%
Update an owner-only mutable snapshot 316,856,781 updates/s 0.0% MAD 316,856,781 updates/s 0.0% MAD 0.0%
Update a synchronized snapshot 1,541,680 updates/s 1.2% MAD 1,547,755 updates/s 1.0% MAD +0.4%
Create, resolve, and await a terminal latch 1,428,514 latches/s 2.3% MAD 1,438,518 latches/s 0.8% MAD +0.7%
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 a0d06e0 into main Aug 9, 2026
9 checks passed
@SandroMaglione
SandroMaglione deleted the codex/compact-child-observation branch August 9, 2026 09:00
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