maruohon / litematica

A modern client-side schematic mod for Minecraft
GNU Lesser General Public License v3.0
728 stars 220 forks source link

very high render distance cause lag, even when not rendering any schematics #480

Open Mari023 opened 2 years ago

Mari023 commented 2 years ago

Minecraft version 1.18.1

Mod version and malilib version litematica-fabric-1.18.0-0.9.0 malilib-fabric-1.18.0-0.10.0-dev.26

A clear description of the issue litematica lags when (moving?) with render distances higher than minecrafts by default allowed 32 chunks, even when it is not rendering anything

(most of the chunks aren't actually loaded, I just have a smaller section cached)

Spark profile: render distance at 256 https://spark.lucko.me/LDJiUwSMGn fi.dy.masa.litematica.render.LitematicaRenderer.piecewisePrepareAndUpdate() takes more than 50%

render distance at 32 https://spark.lucko.me/LNP6xuM1WJ fi.dy.masa.litematica.render.LitematicaRenderer.piecewisePrepareAndUpdate() is just at 1% (which in my opinion is still to much considering it doesn't do anything)

Debug crashlog: https://gist.github.com/Mari023/34de80c166b7efb32e1812ed3ccf0449

I am not sure if this is really worth fixing, since It doesn't apply for normal users.

maruohon commented 2 years ago

The render thread stuff is currently complete FUBAR in Litematica and the actual render threads are actually completely disabled in 1.17+ to prevent them from just crashing the game entirely. I want to entirely rewrite all the rendering stuff at some point via the main development version of the mod in 1.12.2. So hopefully after that this would get fixed. I'm not even sure what is going on here currently if the unlock stuff is the method taking most of the time...

Which mod allows you to go to something like 256 chunk render distance?

Mari023 commented 2 years ago

I'm not even sure what is going on here currently

I think something gets called for every chunk, and given there are 263169 of them in my case, this becomes quite expensive

Which mod allows you to go to something like 256 chunk render distance?

I made my own mod to set the render distance to any arbitrary value. I later found c2me, which also allows higher render distance, but does it in a better way than I did it.

most of the chunks are not actually loaded tho, since I only have some of them cached. (if all were loaded, that would have a much bigger performance impact than litematica)

Mari023 commented 2 years ago

oops didn't mean to close it

maruohon commented 2 years ago

At least the current version of Litematica creates the "chunk renderers" for all sub-chunks within the view distance. That's also what vanilla does or did I believe. No idea how Sodium handles it though. So yes it does call stuff for each sub-section of each chunk within the view distance. But do you mean the actual render distance is not that long, just the "chunk cache distance"? Or how does your thing work? Does it render all chunks that are cached?

Mari023 commented 2 years ago

my mod basically emulates the server sending previously visited chunks.

But do you mean the actual render distance is not that long, just the "chunk cache distance"?

the render distance is whatever it was set, but only chunks that have been visited can be seen (the rest is just empty, similar to chunks which aren't yet send to the client)

nop commented 2 years ago

This issue also causes the game to lag/hang when reloading chunks, for example with F3 + A.

maruohon commented 2 years ago

@nop Does it run out of memory (how much do you have allocated?), or is it just otherwise really slow?

I did one change in mod version 0.10.2 in 1.18.1 that optimized the rendering a LOT for very large schematics. But there are still probably a lot more things that can (and hopefully will) be improved about the renderer once I get to rewriting it all.

nop commented 2 years ago

@nop Does it run out of memory (how much do you have allocated?), or is it just otherwise really slow?

I have 1-4 GB allocated and it has never run out of memory for me. It just causes the game to freeze (not responding, I'm assuming main thread) for around 5-8 seconds every time the chunks are reloaded (F3 + A and upon joining a world). I haven't encountered any freezing when generating new chunks or moving around to load unrendered chunks, only when I use F3 + A (and using mods that reload the chunks to function), joining a world and going through a portal.

I should add that this happens regardless if any schematics are loaded.