orangeadam3 / terra121

A Minecraft Terrain Generating Mod for Cubic Chunks 1.12.2. attempting to generate real terrain, biomes, and features on a 1:1 scale
MIT License
280 stars 41 forks source link

getIdx too slow #111

Open z3nth10n opened 4 years ago

z3nth10n commented 4 years ago

Hi, I'm profiling Terra121 and there is a method that is very CPU expensive and it's lowering my TPS: https://spark.lucko.me/#8NODRBrqtx

The problem is here: https://github.com/orangeadam3/terra121/blob/master/src/main/java/io/github/terra121/dataset/RandomAccessRunlength.java#L33-L52 I don't exactly what this method do.

This is being called at https://github.com/orangeadam3/terra121/blob/master/src/main/java/io/github/terra121/EarthTerrainProcessor.java#L183 (and as I can see this is getting called every on every block for a Cubic Chunks Cube)...

Does anyone know a way to optimize this? I'm thinking about a possible optimization, but I don't why Blocks needs to be replaced.

As I can see you're calculating slopes... Slopes? Terrain slopes? I'm missing documentation here, I don't know what is exactly happening.

(I'm just reviewing the code, so maybe I would edit this later)

orangeadam3 commented 4 years ago

That class is a simple compression skeme to reduce the amount of memory required by the mod. I guess some kind of caching system might help to alleviate this or I could just embrace the increased memory requirements from not using this system. It would increase memory usage by about 50MB by not using this system and just having an array.

z3nth10n commented 4 years ago

Well, I found a bug on your implementation, and it increased world generation speed a lot... The TPS while generating are still on ~5 out of 20. (From ~2/3).

The fix can be seen here: https://github.com/orangeadam3/terra121/pull/112

orangeadam3 commented 4 years ago

Ok I commited a fix that moves some stuff out of for loops. I'm hesitant to use your caching thing, cause I think unpopulated chunks can get saved between games so populators might not always have access to the cache.

z3nth10n commented 4 years ago

Well, I mixed the branches (yep, I didn't want to include those three commits on my patch optimizations branch), so I'll work on a way to disable this setting because it's true that this feature isn't always needed (I need it on my LostCities port). Close this https://github.com/orangeadam3/terra121/pull/81 by now, and I will commit something new later (I'll work also on a caching system for the web requests (you're not doing it, and you can get banned from OSM API if you don't do proper requests, by using a caching system, at least on Nominatim sub API) and pre-generation for the chunks in order to move it to an async scope).