Load island data off the main thread to fix periodic lag spikes - #18
Merged
Conversation
The refresh task ran hook.getAllIslandData() on the main thread every refresh cycle. In both game modes that is a full synchronous database read (Database#loadObjects()), which deserializes every island record ever created and was profiled at up to ~1s per cycle on large servers. refresh(hook) now loads the island data on an async task and hops back to the main thread only for the cheap part: island registry lookups, player/permission checks, and swapping in the new top ten. Placeholder snapshots update per hook as each async load lands. Bump version to 2.1.1. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Um9roAZ8pVAqp6TZEMBjMr
|
Merged
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.



Problem
Server admins reported periodic lag spikes (~160–970 ms, up to a 1,012 ms tick) every refresh cycle, profiled to:
The refresh timer is a sync Bukkit task, and
getAllIslandData()delegates to the game mode'sgetAllIslands(), which is a full synchronous database read (Database#loadObjects()) — it reads and deserializes every island record ever created, on the main thread, every cycle (default 5 min). The cost scales with island count and disk latency, and doubles when both AOneBlock and ChunkBlock are hooked.Fix
refresh(hook)now runsgetAllIslandData()on an async task (pure file I/O + JSON parsing — the same call Level already makes async) and hops back to the main thread only for the cheap part in the newprocessIslandData(): island registry lookups, player/permission checks, and swapping in the new top-ten list. Placeholder snapshots update per hook as each async load completes instead of once after a blockingrefreshAll().This moves essentially the entire refresh cost off the tick loop with no behavior change to the top ten, placeholders, or panel.
Other changes
CommonTestSetupstubs the scheduler to run both legs of the async→sync hop inline so the existing tests stay synchronous.build.versionto 2.1.1; updated CLAUDE.md to document the async/sync split.Testing
mvn test— all 44 tests pass.🤖 Generated with Claude Code
https://claude.ai/code/session_01Um9roAZ8pVAqp6TZEMBjMr