Skip to content

Reduce optimiseRandomTick new BlockPos instance create#505

Open
wling-art wants to merge 10 commits intoWinds-Studio:ver/1.21.11from
wling-art:ver/1.21.4
Open

Reduce optimiseRandomTick new BlockPos instance create#505
wling-art wants to merge 10 commits intoWinds-Studio:ver/1.21.11from
wling-art:ver/1.21.4

Conversation

@wling-art
Copy link
Contributor

@wling-art wling-art commented Sep 20, 2025

Reduce optimiseRandomTick new BlockPos instance creation

This patch optimizes the optimiseRandomTick method in ServerLevel by reusing a single MutableBlockPos instance per thread instead of creating a new immutable BlockPos object on every random tick.

  • Introduces a ThreadLocal<BlockPos.MutableBlockPos> cache to avoid excessive object allocations.
  • Updates the mutable position with .set(...) and converts it to an immutable BlockPos only when passing to randomTick.
  • This reduces memory pressure and potential GC overhead during random block ticking.
  • Ensures thread safety by using ThreadLocal to avoid concurrent modification issues.

Original PR: #332

@Dreeam-qwq Dreeam-qwq added the type: optimization Pull request for optimization label Sep 20, 2025
@Dreeam-qwq Dreeam-qwq changed the base branch from ver/1.21.8 to ver/1.21.11 January 16, 2026 01:57
@Dreeam-qwq Dreeam-qwq added the status: docs update required Config changed, needs the PR author or team member to update docs label Jan 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: docs update required Config changed, needs the PR author or team member to update docs type: optimization Pull request for optimization

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants