Skip to content

ecs: faster first tick after a bulk load - #222

Open
krisnye wants to merge 4 commits into
knye/render-orderfrom
knye/ecs-load-tick
Open

krisnye wants to merge 4 commits into
knye/render-orderfrom
knye/ecs-load-tick

Conversation

@krisnye

@krisnye krisnye commented Oct 22, 2026

Copy link
Copy Markdown
Collaborator

Makes an editor's first tick after a bulk load faster: 31.4–33.2 ms → 20.0–20.4 ms at 50K nodes. up load improves from 221–223 ms to 182–186 ms.

This PR is stacked on #220 (base knye/render-order), so merge #220 first. There's no public contract change. It's in 0.2.0 if it merges before 0.2.0 is published.

Benchmark

New editor load tick 50K. It spawns 50,201 nodes in a tree (a document, 200 groups, 2 subgroups each, 124 shapes and images each), then times one tick of:

  • two filtered up systems;
  • a layout looking up children through a hash index;
  • a paint system ordered by a sorted index.

Changes

Each change was measured alternating against the version without it.

  • Whole order after a rebuild: a filtered up run whose tree was just rebuilt runs the whole order without marking rows one by one. Every row already passed after a rebuild. Tick 32 → 25.1 ms.
  • Parent column read once: the tree build reads each archetype's parent column once instead of looking it up per entity. One walk per entity sets every level during a build, and the order scratch is shared by every up on a thread.
  • Presorted sorted index: a sorted index rebuild skips its sort when entries are already in key order, as a load in document order lists them. Paint 5.6 → 5.1 ms.
  • Ordered rows rebound in place: an ordered run binds its row in place when the archetype changes. Paint 4.85 → 4.5 ms.

One trade, recorded in perf.md: up one root changed goes from 28 µs to 33 µs at 100 rounds, because its sparse path warms up later. After warm-up both take 14 µs. The other up, index and order benchmarks are within noise.

Tests

up.test.ts adds a filtered up overflowing the journal with 5,000 spawns, then one change, then an idle run. pnpm run build and pnpm test in packages/ecs pass: 134 files and 1011 tests.

🤖 Generated with Claude Code

krisnye and others added 4 commits October 22, 2026 01:13
New benchmark `editor load tick 50K`: a 2D editor's first tick after
spawning a 50,201-node tree, with two filtered `up` row systems, a hash
index on the parent and a sorted paint-order index. 32 ms before.

- A filtered run after its tree was built again runs the whole order,
  rather than marking every row and scanning for the marks: the tick
  32 -> 25.1 ms.
- The tree's build reads each archetype's parent column once: the
  opacity `up` 5.35 -> 4.5 ms.
- The build sets every level in one walk per entity: the opacity `up`
  4.77 -> 4.49 ms.
- An order build's scratch is shared by every `up` of a thread: the tick
  20.6 -> 20.0 ms.

`up load` 222 -> 184 ms.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A load in document order lists a paint-order index's entries in key
order already; one pass that stops at the first pair out of order checks
it. `editor load tick 50K`'s paint system 5.6-5.8 -> 5.1-5.3 ms.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A main-thread system run in an index's order looked its shared row up
again whenever the archetype changed, at every row when archetypes
interleave in paint order. `editor load tick 50K`'s paint system
4.85 -> 4.5 ms.

perf.md records the editor load work: `editor load tick 50K`
31.4-33.2 -> 20.0-20.4 ms and `up load` 221-223 -> 182-186 ms against
826c45a, alternating, with the attempts not kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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