Skip to content

ecs 0.6.0, ecs-persistence 0.2.0: save, restore and watch values a trait covers on any thread - #284

Merged
krisnye merged 2 commits into
mainfrom
krisnye/persistence-across-threads
Nov 23, 2026
Merged

krisnye merged 2 commits into
mainfrom
krisnye/persistence-across-threads

Conversation

@krisnye

@krisnye krisnye commented Nov 22, 2026

Copy link
Copy Markdown
Collaborator

Closes #283.

@adobe/ecs-persistence now saves, restores and watches every value a trait covers, on whichever thread holds it.

@adobe/ecs 0.6.0

  • Values sent to other threads: commands, spawns and commands.spawnTables on the world's thread may give data (a type with a schema, not transfer) to an object a joined thread holds. The value goes there by message and is set at the sync point through the move log. Replay waits for a message that hasn't arrived, and the world never waits for delivery. Values that aren't data are still refused.
  • spawnTables fixes: it rewrites entity values in the resources it sets, and refuses only a resource a joined thread holds that isn't data, not every resource declared on another thread.
  • tables from other threads: a readonly system's tables asks each joined thread for the values it holds and merges them by entity. Objects of other threads no longer place a tables system on that thread.
  • New API, trait filter: System.create({ readonly: true, changed: [trait] }, ...) runs only once something declaring the trait changed, on any thread: a write, an add or remove, or a spawn or despawn. It runs only on the world's thread; a joined thread's own system that declares it is refused.
  • CLAUDE.md now states that the core is minimal and performance-first.

@adobe/ecs-persistence 0.2.0

  • snapshot and spawn cover values on any thread.
  • New watch({ world, by }, onChange), which returns a function that stops it.
  • New guide chapter, "Saving as it changes". The README has new sections on values on other threads and on saving as it changes.

Tests and performance

  • New tests:
    • the move-log property test covers values sent to other threads, including replay waiting for a message that hasn't arrived;
    • tests for joined-thread spawns and resources, tables reads from other threads, the trait filter, and rewriting entity values in resources;
    • persistence across threads.
  • Ran locally after deleting every *.tsbuildinfo: check:workspace and build pass, and every package's tests pass. Three tests timed out under load and passed when rerun alone.
  • pnpm perf: all 188 node benchmarks were compared with a run on unchanged code. The differences stay within the spread of repeated runs on unchanged code, so no regression. New benchmarks: trait notice quiet 100K costs 347 ns per run with nothing changed, and trait notice written 100K measures a run that writes one row of a component declaring the trait.
  • No new record in perf/history: the machine was too busy for a reliable one. Record on an idle machine before merging.

…ait covers on any thread (#283)

- World-thread commands, spawns and spawnTables give joined threads' data objects values, delivered by message and
  applied at the sync point through the move log.
- spawnTables rewrites entity values in the resources it sets, and refuses only a resource a joined thread fills that
  isn't data.
- Readonly systems' tables gather the values joined threads hold, merged by entity.
- Readonly systems may filter on traits: changed: [trait] runs them once something declaring the trait changed, on any
  thread.
- ecs-persistence: snapshot and spawn cover values on any thread; watch({ world, by }, onChange); guide chapter 5.
@krisnye
krisnye merged commit 1b41b49 into main Nov 23, 2026
4 checks passed
@krisnye
krisnye deleted the krisnye/persistence-across-threads branch November 23, 2026 17:53
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.

ecs-persistence: save, restore and watch values a trait covers on any thread

1 participant