Skip to content

Reduce optimiseRandomTick new BlockPos instance create#505

Merged
Dreeam-qwq merged 12 commits intoWinds-Studio:ver/1.21.11from
wling-art:ver/1.21.4
Feb 25, 2026
Merged

Reduce optimiseRandomTick new BlockPos instance create#505
Dreeam-qwq merged 12 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
Copy link
Member

@Dreeam-qwq Dreeam-qwq left a comment

Choose a reason for hiding this comment

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

Gooood

@Dreeam-qwq Dreeam-qwq merged commit ba59b8d into Winds-Studio:ver/1.21.11 Feb 25, 2026
1 check passed
@wling-art wling-art deleted the ver/1.21.4 branch February 26, 2026 00:52
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.

3 participants