Skip to content

perf(world): write immediate spawns in place - #13

Merged
Stephanvs merged 1 commit into
mainfrom
feat/step8-in-place-spawn
Oct 30, 2026
Merged

Stephanvs merged 1 commit into
mainfrom
feat/step8-in-place-spawn

Conversation

@Stephanvs

Copy link
Copy Markdown
Owner

Roadmap step 8. World.Spawn<TBundle> and World.SpawnBatch<TBundle> no longer stage each bundle in a buffer and copy it into the table. They append the row first, and the bundle's Write stores each member directly in its destination column.

Change

  • BundleWriter has two targets. The staging form is unchanged and still serves Commands and InsertBundle. The new table form writes each member into its column through BundleBinding.Columns and stamps tracked ticks.
  • If Write or Complete throws, Spawn truncates the row and releases the reservation, as SpawnBatch already did for the whole batch. The change tick advances only after a successful write.
  • While Write runs, the new row is in the table but not yet in the entity directory, so the world counts as running for that window. A bundle whose Write reaches the same world now throws, instead of moving or truncating the row being written. The old staging path did not need this guard.

Measurements

Six interleaved process runs, with before at 1ea88b7. Medians in µs; full conditions and ranges are in benchmarks/step8-in-place-spawn.md.

Case Before After After/before
Spawn, 1,000 43.10 28.16 0.65
Spawn, 100,000 5,404 3,999 0.74
SpawnBatch, 1,000 26.73 16.16 0.60
SpawnBatch, 100,000 3,193 2,201 0.69

Managed allocation is unchanged. Despawn, Get<T>, and the round trips run no changed code, and they moved within ±5%.

Gate

  • Spawn and batch spawn improve at both sizes, and allocate no more memory: met.
  • Spawn, batch spawn, and command tests pass, including partial writes that must leave no row or reservation: met. Two tests are new: Spawn_that_fails_partway_leaves_no_row_or_reservation and Bundle_write_cannot_spawn_into_the_world_it_is_writing_to.
  • scripts/verify.ps1 passes locally.

🤖 Generated with Claude Code

@cloudflare-workers-and-pages

Copy link
Copy Markdown

🚀 Deploying Preview to Cloudflare 🚀

Preview URL: https://feat-step8-in-place-spawn-archevolt.hayman.workers.dev (commit 55e02fd)

This URL reflects your latest Preview deployment

Preview Deployments by commit

Status Deployment URL Commit Updated (UTC) See this deployment's details
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://0638aad4-archevolt.hayman.workers.dev 55e02fd 2026-10-30T22:39:43.751Z Visit the dashboard ↗

@Stephanvs
Stephanvs merged commit bc62d14 into main Oct 30, 2026
2 checks passed
@Stephanvs
Stephanvs deleted the feat/step8-in-place-spawn branch October 30, 2026 22: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.

1 participant