Skip to content

ProcGen & Scene Static Upload Memory Optimizations#1061

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

ProcGen & Scene Static Upload Memory Optimizations#1061
RuffledPlume wants to merge 150 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 13 times, most recently from fbd66a6 to cb22396 Compare May 1, 2026 21:46
@RuffledPlume RuffledPlume force-pushed the ProceduralGeneratorAllocFree branch from aaaf37e to 7a1dd70 Compare May 21, 2026 17:39
@RuffledPlume RuffledPlume force-pushed the ProceduralGeneratorAllocFree branch from ad760a4 to 82c7b5e Compare May 24, 2026 01:31
@RuffledPlume RuffledPlume force-pushed the ProceduralGeneratorAllocFree branch from e5d3e01 to 54a730f Compare May 24, 2026 02:14
@RuffledPlume RuffledPlume force-pushed the ProceduralGeneratorAllocFree branch from ea5b18e to 330ec40 Compare May 24, 2026 23:02
@RuffledPlume RuffledPlume force-pushed the ProceduralGeneratorAllocFree branch from ca0d9e9 to cbc2eca Compare May 26, 2026 11:19
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