Skip to content

Replace IslandGrid nested TreeMap with spatial hash#2840

Merged
tastybento merged 1 commit intodevelopfrom
spatial-hash-island-grid
Mar 13, 2026
Merged

Replace IslandGrid nested TreeMap with spatial hash#2840
tastybento merged 1 commit intodevelopfrom
spatial-hash-island-grid

Conversation

@tastybento
Copy link
Member

@tastybento tastybento commented Mar 13, 2026

Summary

  • Replaces the nested TreeMap internals of IslandGrid with a cell-based spatial hash (HashMap), reducing island loading from O(n²) to O(n) — fixes Bentobox 3.11.1 not loading on paper 1.21.8 #2838 where servers with many islands hang at "Loading islands from database.."
  • Fixes a correctness bug in getIslandStringAt() where the floorEntry() approach missed large islands at lower X keys when smaller islands existed at closer X coordinates — critical for Stranger Realms arbitrary island positions
  • Replaces getGrid() with getAllIslands() and getIslandsInBounds(), updating AdminPurgeRegionsCommand accordingly

Test plan

  • Run ./gradlew clean build — all existing + 8 new IslandGrid tests should pass
  • Verify island loading time on a server with many islands (the reporter's server would be ideal)
  • Verify player movement doesn't cause lag (getIslandStringAt is on the hot path)
  • Test AdminPurgeRegionsCommand still works correctly
  • Test with Stranger Realms arbitrary-position islands

relates to #2838

…ding

The nested TreeMap implementation had O(n²) complexity during island loading
due to full-grid scans in removeFromGrid() and headMap() overlap detection.
This caused servers with many islands to hang at "Loading islands from
database.." (fixes #2838).

Also fixes a correctness bug in getIslandStringAt() where the floorEntry()
approach could miss large islands at lower X keys when smaller islands
existed at closer X coordinates — critical for arbitrary island positions
(Stranger Realms).

Replaces internals with a cell-based spatial hash (HashMap<Long, Set<String>>)
giving O(1) average-case point lookups, O(c×k) insertion with overlap
detection, and O(c) removal. Replaces getGrid() with getAllIslands() and
getIslandsInBounds() and updates AdminPurgeRegionsCommand accordingly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@tastybento tastybento force-pushed the spatial-hash-island-grid branch from cfa114f to 7292b3e Compare March 13, 2026 01:20
@sonarqubecloud
Copy link

@tastybento tastybento merged commit ff3aec5 into develop Mar 13, 2026
3 checks passed
@tastybento tastybento deleted the spatial-hash-island-grid branch March 13, 2026 01:29
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.

Bentobox 3.11.1 not loading on paper 1.21.8

1 participant