Skip to content

Optimize retained VoxelShape memory usage - #195

Open
wphillipp wants to merge 1 commit into
Tuinity:mc/26.2from
wphillipp:perf/optimize-retained-voxelshape-memory
Open

Optimize retained VoxelShape memory usage#195
wphillipp wants to merge 1 commit into
Tuinity:mc/26.2from
wphillipp:perf/optimize-retained-voxelshape-memory

Conversation

@wphillipp

Copy link
Copy Markdown

Summary

This PR reduces memory retained by VoxelShape collision caches by sharing immutable geometry data that is duplicated across many shapes.

The main change is that geometry is no longer interned during normal VoxelShape construction. Shapes created by collisions, joins or moves can be short-lived, so interning them globally would add unnecessary runtime overhead.

Instead, retained geometry is promoted when it reaches a known long-lived owner, currently the BlockState collision caches.

Changes

  • Added bounded interning for coordinate lists, cached voxel data, discrete voxel shapes and cached AABBs.
  • Added retained-geometry promotion for shapes stored in BlockState caches.
  • Kept transient/runtime-generated shapes out of the global pools.
  • Reduced duplicated retained cache data.
  • Kept all pools bounded to avoid unbounded process-lifetime growth.

Memory impact

Measured against the unmodified base using the same world/config snapshot and a full GC before each measurement:

Heap after Full GC
Baseline median 217.932 MiB
Optimized median 137.806 MiB
Saved 80.126 MiB (36.767%)

Some of the largest retained object reductions:

Type Baseline Optimized
CachedShapeData 170,165 1,611
BitSetDiscreteVoxelShape 170,165 1,611
DoubleArrayList 353,936 4,438
AABB 417,470 1,613
CachedToAABBs 171,389 0

The number of ArrayVoxelShape instances itself stays unchanged, so the reduction comes from sharing duplicated retained data rather than avoiding shape creation.

Validation

Functional behaviour was compared against the base revision using a deterministic black-box oracle based on public Minecraft APIs.

Both versions produced byte-identical results, and the Mixin audit passes for both builds.

A separate runtime A/B benchmark also showed no material regression in the collision and shape hot paths.

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