Skip to content

ProcGen & Scene Static Upload Memory Optimizations#1061

Open
RuffledPlume wants to merge 97 commits into
117HD:masterfrom
RuffledPlume:ProceduralGeneratorAllocFree
Open

ProcGen & Scene Static Upload Memory Optimizations#1061
RuffledPlume wants to merge 97 commits into
117HD:masterfrom
RuffledPlume:ProceduralGeneratorAllocFree

Conversation

@RuffledPlume
Copy link
Copy Markdown
Contributor

@RuffledPlume RuffledPlume commented Apr 24, 2026

Main:

DEBUG r.h.s.ProceduralGenerator      - procedural data generation took 238ms to complete
DEBUG r.h.s.ProceduralGenerator      - -- calculateTerrainNormals: 33ms (104 MB)
DEBUG r.h.s.ProceduralGenerator      - -- generateTerrainData: 128ms  (57 MB)
DEBUG r.h.s.ProceduralGenerator      - -- generateUnderwaterTerrain: 77ms  (423 MB)
image

PR:

DEBUG r.h.s.ProceduralGenerator      - procedural data generation took 44ms to complete
DEBUG r.h.s.ProceduralGenerator      - -- calculateMainTileOverrides: 8ms (19 MB)
DEBUG r.h.s.ProceduralGenerator      - -- calculateTerrainNormals: 10ms (27 MB) 
DEBUG r.h.s.ProceduralGenerator      - -- generateTerrainData: 18ms (14 MB)
DEBUG r.h.s.ProceduralGenerator      - -- generateUnderwaterTerrain: 8ms (37 MB)
image

Key Changes

Introduces Primitive Collections

  • Int2IntHashMap
  • Int2ObjectHashMap
  • IntHashMap
    Using Base Java Collections with generic type means any function call taking a key/value of that type will allocate since it will need to box the primitive type with the object version, which in hot path leads to MBs of garbage being generated.

ProceduralGenerator

  • tileVertexKeys & faceVertexKeys now all use preallocated arrays instead of allocating on each call
  • Combined isWaterTile & skipTile arrays int a byte[][][] tileFlags
  • Each step will presize their collections based on previous scene context if present & valid
  • Added New Step: MainTileOverridesGenerator
    • PreCalculates TileOverrides for all tiles within the scene, avoiding it being resolved multiple times
    • Uses Previous Scene Context to copy tiles which can be reused

Area

  • Added areaBounds AABB which acts as an early rejection
  • If there is more than 4 AABBs then it'll sort AABBs based on distance from the corners of the area + their size

@RuffledPlume RuffledPlume force-pushed the ProceduralGeneratorAllocFree branch 6 times, most recently from 82dcec3 to 19f993d Compare April 25, 2026 01:21
@RuffledPlume RuffledPlume changed the title Procedural generator alloc free ProcGen & Scene Static Upload Memory Optimizations Apr 25, 2026
@RuffledPlume RuffledPlume force-pushed the ProceduralGeneratorAllocFree branch 8 times, most recently from 947521e to 5ca39ca Compare April 28, 2026 21:19
@RuffledPlume RuffledPlume force-pushed the ProceduralGeneratorAllocFree branch from 51bbc8b to d50e793 Compare April 30, 2026 16:50
 * Buckets can only go up to 30, 31/32 are invalid since int is signed
 * When borrowing, we need to round up to the nearest pow2
@RuffledPlume RuffledPlume force-pushed the ProceduralGeneratorAllocFree branch from 1bda257 to c6fe7a5 Compare April 30, 2026 16:52
Use Stamps to avoid having to clear zSortHead & zSortTail
Track toched LinkSets instead of the min/Max fZ which significantly reduces the amount of buckets it has to loop through
@RuffledPlume RuffledPlume force-pushed the ProceduralGeneratorAllocFree branch from 2c45797 to a37cd9c Compare April 30, 2026 20:55
@RuffledPlume RuffledPlume force-pushed the ProceduralGeneratorAllocFree branch from 3a29acb to 6472a8a Compare May 1, 2026 20:31
@RuffledPlume RuffledPlume force-pushed the ProceduralGeneratorAllocFree branch from fbd66a6 to cb22396 Compare May 1, 2026 21:46
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