Skip to content

transaction improvement#7

Open
HashimTheArab wants to merge 7 commits into
lunarfrom
refactor/tx-improvement
Open

transaction improvement#7
HashimTheArab wants to merge 7 commits into
lunarfrom
refactor/tx-improvement

Conversation

@HashimTheArab

@HashimTheArab HashimTheArab commented Jan 25, 2026

Copy link
Copy Markdown
Owner

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.

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 background Provider.LoadColumn + per-chunk lighting Fill() job that later installs the chunk via a short World.Exec() transaction.

Moves chunk persistence off the transaction path for unloads by adding a background save queue and switching closeUnusedChunks() to unload via closeChunkAsync(); 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, and tick() phases.

Reviewed by Cursor Bugbot for commit 04aa2d1. Bugbot is set up for automated code reviews on this repo. Configure here.

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.
@coderabbitai

coderabbitai Bot commented Jan 25, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: af1de7cd-f7bf-464b-8fa3-1909d7144eb7

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/tx-improvement

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.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Comment thread server/world/prefetch.go
Comment thread server/world/prefetch.go
Comment thread server/world/loader.go
Comment thread server/world/prefetch.go

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ 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.

Comment thread server/world/world.go
Comment thread server/world/world.go
}
clear(c.Entities)
delete(w.chunks, pos)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit edf7866. Configure here.

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