What I can do to reduce memory usage in infinite mining game?

Hello, guys. I’m making mining game.

Today, I though I finished mining system - I did infinite mine generation, ores, some ways to dig.
But when I opened Performance stats, I understood that my mine is far-far from finishing.

(I was testing in studio, because of new Roblox byfron, so can’t test in Roblox Player)
Blank baseplate in studio, uses around 2k mb memory
image
But when I looked in my mine game, I understood that my system uses TOO much memory:


And that 3k Mb is just spawning, not counting that player will move, and load new chunks:

4.4K MB IN UNDER THAN MINUTE!
(IDK, is studio counts memory used by “Server”)

Now some things about my system:

  1. It uses chunk system. Each chunk is cube 16x16x16 blocks.
  2. Block is always part with size 1x1x1 stud.
  3. Chunks are generating on server, but only if:
  • player send request to load chunk(-s);
  • cave requested to load certain chunk;
  1. Client unloads chunk, if it too far from it, with: MineSystem[X][Y][Z] = nil
  2. Server unloads ALL chunks exept chunks near players once every 15 minutes

So I think this memory primarly from server, because I don’t unload anything from it for 15 mins. Because if player will go from point A to point B, unload chunks at A, and then went back to it, player will expect to see everything that was before.

And now I realized that I need do something with this absurd memory usage, or everyones devices will run out of memory (or roblox servers xd).
Can someone tell me please, what I can do, to decrease memory usage?

P.S.
After looking at Dev Console, I found that Instances use only 80 mb
Most memory used by LuaHeap and Script (800mb and 300mb respectively)
Also, A lot of memory is “Untracked” - 800 mb

Only spawn the blocks the player can see, when they break blocks spawn blocks back around it. Store any air blocks so that you know which blocks not to fill back up.

I’m already doing that. Blocks are exist as Part only if any it’s neighbor is “Air”

You shouldn’t use studio memory as an indication of high memory usage. Try to test it in a real game.

The server also shouldn’t be the one loading and unloading chunks, everything like that should just be done on the client. As long as you make sure that everyone has the same chunks that should be fine. It’ll lower the memory usage by a lot since everyone is only loading for theirself, instead of the server replicating all chunks to all clients.

Though, without any code we wouldn’t even be able to help since this just seems like some kind of memory leak. I get that you “MineSystem[X][Y][Z] = nil” which probably means that you remove the reference to the part after you destroy it but there can be a lot more to it than that.

I’m already doing that. Blocks are exist as Part only if any it’s neighbor is “Air”

Keep in mind that that doesn’t need to include diagonal neighbors.

  1. I can’t test my system in Roblox Player. I’m windows-7 user, adn roblox blocked me with their Byfron system.
  2. Server not creating any parts. It loads chunk data, generates ores and caves, but only in values like MineSystem[X][Y][Z][1][BX][BY][BZ] = {“Stone”, 3, }
    Then, if player requested, server sends chunk data MineSystem[X][Y][Z][1] to player, and player loads chunk blocks.
  3. Block will be loaded only if 1+ out of 6 nearby blocks (which are +X, -X, +Y, -Y, +Z, -Z) are Air. Otherwise, they just exist as some value data in 8D array, but not in parts.
  4. MineSystem[X][Y][Z] = nil is used by client. So, chunkdata on client will be cleared. Server still have that chunk data, so if player will come back, server will just send already generated data back to client.

Huh are you sure you need an 8D array just to store information on what is in a 3D position?

I think I need that 8d array:

First 3 arrays - are Position of Chunk. XYZ. No chunk - then corresponding array will be nilled
4-th array consist of 2 variables - ChunkData and number <0, 1>, representing, saw that chunk player (if player saw chunk, then it can’t be affected by cave generation again)
5-7 - ChunkData, Position of every block in XYZ. Always have value. (Also, chunk size is 16x16x16)
8-th BlockData. Contains Blocks type, durability, and tags, if there’s any.

First 3 arrays - are Position of Chunk. XYZ. No chunk - then corresponding array will be nilled

Chunks could only be on XY, you can just make the chunk have a height limit like minecraft does it so you can get rid of the Z dimension.

Besides that I guess it does make sense, not too sure how you could improve that. Though until you find a way to start Roblox Player again, you shouldn’t worry too much about the memory usage. The memory usage in a game like this might always just be on the higher end compared to other games.

I don’t think removing Z coordinate representing height of chunk will be good idea, because I assume that player can dig down like much more than 256 or 512 blocks, but like 10k or more.

Oh I see, nevermind then. I think it’s fine as it is, you’ll have to see the actual performance in a real game whenever you have the chance to.