Eldemarkki / Marching-Cubes-Terrain

Marching Cubes terrain implementation in Unity using the Job System and the Burst compiler
MIT License
565 stars 80 forks source link

Memory Usage #25

Closed HellGate94 closed 4 years ago

HellGate94 commented 4 years ago

I saw you already changed to a byte density model and that's nice, yet the memory usage huge (about 10gb for a view distance of 7).

this seems mostly because of keeping the mesh data arrays after mesh generation for each chunk. i don't think you need this data after updating the mesh renderer.

maybe if you implement the chunk loading over time limit (max x chunks at a time) you could implement a pool of x for this data to reduce the memory without having to allocate new memory space each time

Eldemarkki commented 4 years ago

I will take a look at this today!

Eldemarkki commented 4 years ago

I tried the old version myself with render distance of 7, and the memory usage was about 6gb (not quite 10gb, but that is still a lot). I then did some changes and disposed the mesh data arrays after generation and the memory dropped to around 1.8gb with render distance of 7. Pushed these changes to the develop branch.

All testing was done using both Unity's profiler and Win10 task manager with a built version of the game (= not in editor)

HellGate94 commented 4 years ago

perfect! yea the editor profiler reports about 6gb of nativearray data. the rest most likely comes from the mesh renderer mesh data and editor things

HellGate94 commented 4 years ago

while the memory usage during runtime is much lower now at startup when all chunks are build it still spikes and runs out of memory. but that's for the chunk loading over time issue imo

Eldemarkki commented 4 years ago

Yes, I will be implementing the async chunk loading within a few days maybe, that should help both memory usage and the lag spikes.