Repository navigation
feat(world): add lock-free reservation and SpawnBatch - #11
Merged
Merged
Conversation
A failed SpawnBatch no longer consumes a change tick, which matches Spawn<TBundle>. EntityTable.Reserve for a span now reuses the single-entity reservation after growing the directory once. ROADMAP step 8 now names SpawnBatch in its scope and gate, because step 5 still stages each bundle. Step 5's Bevy precedent now states that Archevolt keeps a flush for command-buffer claims. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
🚀 Deploying Preview to Cloudflare 🚀Preview URL: https://feat-step5-lock-free-reservation-archevolt.hayman.workers.dev (commit 8a9dd22)This URL reflects your latest Preview deploymentPreview Deployments by commit
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Every spawn and despawn took a lock on the entity directory, even on the idle owner thread, and there was no way to spawn many entities at once. This is ROADMAP step 5. The owner thread now reserves and releases slots without a lock. Systems that call
Commands.Spawnclaim a slot with one atomic decrement. A newWorld.SpawnBatchspawns a whole span of bundles in one call.Scope
EntityAllocatorowns the free list and a signed claim cursor.EntityTablekeeps generations, states, locations, and the next fresh index.EntityTable.ReserveConcurrenthandles command-buffer claims.EntityTable.Flushrecords pending claims before playback, before discard, and when a run exits.World.SpawnBatch<TBundle>(ReadOnlySpan<TBundle>, Span<Entity>)reserves every handle, grows the table once, and uses one change tick. If any bundle fails to write, it truncates the rows, releases every reservation, and clears the handles. A failed batch consumes no tick.ROADMAP.mdadds amendments after step 5. Step 8's scope and gate now includeSpawnBatch, because batch spawn still stages each bundle.Tradeoffs
The design keeps a flush step, unlike the Bevy 0.18 precedent. A claim only moves a cursor and never writes to the directory, so directory pages grow only on the owner thread.
Blast Radius
This changes entity reservation for every spawn path, and adds one public API. Merging releases v0.5.0, because the release workflow publishes every push to
mainandfeatis a minor bump.Verification
scripts/verify.ps1passed: 164 tests, Archeoids headless, package contents, JIT and NativeAOT consumers, the NativeAOT sample, and the performance smoke check.SpawnBatchtook 3,737 µs against 5,905 µs for individual spawns. Spawn went from 6,361 to 5,905 µs, and despawn from 5,986 to 4,934 µs. Full tables are inbenchmarks/step5-lock-free-reservation.md.EntityPopulationBenchmarksafter the review fixes showed no regression from the simplified batch reservation (SpawnBatchat 100,000 entities: 3,635 → 3,577 µs).🤖 Generated with Claude Code