Skip to content

Optimize block iteration to prevent memory leaks#119

Open
LetMePractice wants to merge 1 commit intoclickcrystals-development:mainfrom
LetMePractice:main
Open

Optimize block iteration to prevent memory leaks#119
LetMePractice wants to merge 1 commit intoclickcrystals-development:mainfrom
LetMePractice:main

Conversation

@LetMePractice
Copy link
Contributor

Type of change

  • Bug fix
  • New feature

Description

Reworked block iteration to stop allocating new BlockPos objects inside hot loops.

The old implementation was creating a new BlockPos per iteration. Under heavy scripting this adds up to millions of allocations over time and eventually causes GC pressure and long-session instability.

Changes

  • PlayerUtils.boxIterator() now uses BlockPos.Mutable
  • runOnNearestBlock() / getNearestBlock() switched from cubic scan to spiral search and reuse a mutable position
  • EntityUtils.runOnNearestBlock() updated the same way
  • Raytracer.trace() reuses a single BlockPos.Mutable
  • ConditionalBlockInFov rewritten to use a 3x3 raycast grid instead of block iteration

Impact

  • Significantly lower allocation rate in hot paths
  • Faster early exits with spiral search
  • Removes sustained allocation pressure from block iteration

Related issues

Fixes long-session black screen when block_in_range / block_in_fov are used heavily in scripts.

Checklist:

  • My code follows the style guidelines of ItziSpyder(ImproperIssues).
  • I have added comments to my code in more complex areas.
  • I have tested the code in both development and production environments.
  • I have joined the ClickCrystals Discord.

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