transaction improvement#7
Conversation
I added an async prefetch pipeline in server/world/prefetch.go and changed Loader.Load() to: - Never call tx.w.chunk(pos) on a missing chunk. - Instead, schedule a background prefetch job (requestPrefetch) and retry later. The prefetch job runs outside the world transaction goroutine and does: - Provider.LoadColumn (disk I/O off-tx) - LightArea(...).Fill() (per-chunk lighting off-tx) - then installs the result using a short world transaction (inserts into w.chunks, attaches entities, then does cross-chunk spreading via w.calculateLight(pos)). Benefits - Removes disk I/O from the world tx path for chunk streaming. - Removes the expensive “Fill” lighting pass from the world tx path (this is typically the biggest CPU chunk-light cost). - In practice this should reduce tick spikes / input lag when players move into new areas, because chunk misses no longer block all transactions.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit edf7866. Configure here.
| } | ||
| clear(c.Entities) | ||
| delete(w.chunks, pos) | ||
| } |
There was a problem hiding this comment.
Duplicated chunk teardown logic across two functions
Low Severity
closeChunkAsync duplicates the entity-closing, entity-clearing, scheduled-tick-removal, and chunk-deletion logic from closeChunk. A bug fix in one (e.g., changing the entity teardown order) could easily be missed in the other. The only difference between them is the save method (sync vs. async), so the shared teardown steps could be factored into a common helper.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit edf7866. Configure here.


I added an async prefetch pipeline in server/world/prefetch.go and changed Loader.Load() to:
The prefetch job runs outside the world transaction goroutine and does:
Benefits
Note
Medium Risk
Introduces new background goroutines and shared-state coordination for chunk loading/saving and scheduled-tick indexing, which can impact world consistency and performance if there are race/ordering bugs or queue saturation edge cases.
Overview
Reduces stalls on the world transaction goroutine by introducing an async chunk prefetch pipeline:
Loader.Load()no longer synchronously loads missing chunks, and instead enqueues a backgroundProvider.LoadColumn+ per-chunk lightingFill()job that later installs the chunk via a shortWorld.Exec()transaction.Moves chunk persistence off the transaction path for unloads by adding a background save queue and switching
closeUnusedChunks()to unload viacloseChunkAsync(); synchronous saves (saveChunk) now go through the same pipeline and can wait for completion.Refactors scheduled block updates to use a min-heap + per-chunk index (with cancellation) to avoid scanning all pending ticks when unloading/saving chunks. Adds periodic world performance metrics logging (enqueue/tx/tick timings and dropped prefetch count) and instruments
Exec, transactions, andtick()phases.Reviewed by Cursor Bugbot for commit 04aa2d1. Bugbot is set up for automated code reviews on this repo. Configure here.