PneumaticCraft: Repressurized

PneumaticCraft: Repressurized

43M Downloads

Block State Lagspikes in Chunks w/ PneumaticCraft Activity

HipHopHuman opened this issue ยท 23 comments

commented

Minecraft Version

1.16.4

Forge Version

35.1.7

Mod Version

1.16.4-2.7.2-87

Describe your problem, including steps to reproduce it

I've been experiencing some marginal performance issues that I'm not quite sure how to properly explain, but I'll try my best. Whenever I am in a chunk where there is a drone doing work, or where there is a heat-producing machine dispersing its heat to heat sinks, or an Air Grate module attracting/repelling entities, there are noticeable lag spikes whenever a block state event happens in that same chunk. This could be me or a drone breaking a block, placing a block, opening a chest, or a furnace starting to cook, a piston being pushed, redstone being powered, etc.

Normally I get around 300fps. When the lag spike ocurrs, this drops to 120fps, but there is a noticeable freeze on the screen that lasts 1-2 seconds, which indicates that the fps number the F3 debug screen is showing me is not accurate, as the freeze seems to be around 2-4fps (an eyeballed estimate).

Originally I thought that this was just because of some weirdness regarding some other performance related mods I had installed, so I thought nothing of it (It's worth noting that I am doing a playthrough of PNC alone, with no other mods except Comforts + Xaero's + JEI and some performance mods). However, now that my base is getting large and my infrastructure is growing, the lag is starting to intrude on my gameplay.

So I decided to investigate every possible cause. I created a fresh new pack with nothing but JEI and PNC and their dependencies. I tested it on MultiMC, GDLauncher and the new Overwolf CurseForge. I tested it with 4GB, 6GB and 8GB of RAM allocated. I tested it with all of those launchers' various default Java args, as well as my own args:

-XX:+UseG1GC -Dsun.rmi.dgc.server.gcInterval=2147483646 -XX:+UnlockExperimentalVMOptions -XX:G1NewSizePercent=20 -XX:G1ReservePercent=20 -XX:MaxGCPauseMillis=50 -XX:G1HeapRegionSize=32M

I have also tried setting the priority of the game to "High" via task manager, doing a resource reload via F3+T and reducing the Mipmap levels to 0.

Despite all this testing, the block state lag persists. It's worth noting that I never experienced any of this lag in 1.12.2, PNC was very smooth in that version performance-wise. I haven't played any version of PNC between 1.12.2 and 1.16.4, so I cannot comment on them.

I think this may be related to this Vanilla MC issue: https://bugs.mojang.com/browse/MC-192845

It's also worth noting that I am not playing on a low-end PC. These are my specs:

AMD Ryzen 7 1700 Eight-Core Processor, 3000 Mhz, 8 Core(s), 16 Logical Processor(s)
24,0 GB RAM
GeForce GTX 1060 6GB

Any other comments?

I am not sure what else I can provide to help iron this out, but if you need a logfile or anything then let me know, I'll be happy to assist.

commented

OK, the pressure tube performance improvement is in build 88.

@duncanwebb it's possible this will help with some of the performance issues you saw in your world too. I haven't backported to 1.15, but I think you've fully moved to 1.16 now anyway?

commented

Hi @desht, thanks for the hard work. Just tested build 88 on a single-player world and unfortunately the lag spikes still remain. As far as I've tested there's virtually zero difference between this build and the last (from the player's perspective). The most noticeable performance drops I get involve drones (specifically when they break blocks, especially leaves) and blocks that propagate heat (when blocks are broken around them), so I think those areas are a good place to look next.

commented

Any chance you could get another visualvm dump for me to analyse? Taken while you're experiencing the FPS drops. And just to confirm, this is FPS rather than TPS drops, right?

commented

I will do so later tonight, a little busy at the moment, but to answer your question it's a little weirder than that... The "fps" number on the F3 screen doesn't actually drop at all, it still reports 100+ fps, but the game definitely freezes the frame and behaves as if it is dropping to 2 fps or so. I'll take a video to hopefully show it better

commented

Alright, so I took a video. While the video clearly documents the performance issues, I will mention that they are not as bad in the video as I have experienced while not recording. I tested this theory with OBS turned off and the FPS drops considerably more, so I think OBS is helping somehow...? O_o Anyway, here's the video: https://streamable.com/tev8gn

I will now get started doing a VisualVM profile and will get back to you in a few.

commented

Alright, here you go: pneumaticraft-performance.zip

During this performance profile I loaded the world in the video, walked over to the Advanced Air Compressor, placed a few dirt blocks, broke a few dirt blocks, then flew back to the Harvester Drone, dissassembled it, placed a new one and had it harvest a grown oak sapling.

commented

OK, the pressure tube performance improvement is in build 88.

@duncanwebb it's possible this will help with some of the performance issues you saw in your world too. I haven't backported to 1.15, but I think you've fully moved to 1.16 now anyway?

Sure, no problem, I'll see if this build 88+ helps.

commented

OK, 2.8.1 (just released) should help with this, I hope.

I did noticed when testing with Alt-F3, regular spikes in the FPS graph which are gone with the latest changes (although I wasn't having any perceivable FPS stutter). So give it a go & let me know how it's working.

This build should also make pressure gauge rendering a bit more performant (poly count in the drawing the gauge face was higher than it needed to be).

commented

Just installed 2.8.1 and the performance increase I'm experiencing is massive, this is great!! Went from 5 fps to 30 fps. Thank you so much for your hard work!

commented

I also experienced quite a bit of lag (down to 5 fps) and ran the Spark profiler with samples from ticks that took over 300 milliseconds to complete and "BlockPneumaticCraftCamo.getUncamouflagedCollisionShape()" and further down the line "BlockPressureTube.getUncamouflagedShape()" seem to be the source of that lag, at least from what I can tell.
Here are the relevant bits of the log:
https://i.imgur.com/XaxG5TC.png

I'm not really much of a coder myself, so apologies if this is not of any use or if I read things the wrong way.
I was not looking at any pressure tubes while I was profiling, but I was standing in the same chunk and there's quite a bit of PNCR machinery around. The chunk is force-loaded and when I leave the area, things get back to normal rather quickly (to my v-sync capped 60 fps).

Version is: 1.16.4-2.8.0-95

commented

Yeah, I think you're on the right track there. Pretty sure there's still something up with the pressure tube shape calculation, but my test worlds aren't displaying the problem right now, so having some trouble tracking it down...

commented

Alright, so finally had some time to give this a test and you've outdone yourself @desht - all the lag I was experiencing around pressure tubes and heat propagation blocks is entirely gone. I've noticed very intermittent frame drops here and there, but they're infrequent and last no more than a tenth of a second (and to be honest I think they're being caused by The One Probe, not PNC), so it's playable!

I tested Drones as well to see if any of this might have positively affected the lag I was experiencing with them, but unfortunately it appears they still are rather laggy - only in singleplayer, however. They're completely lag free in a multiplayer environment. I can finally get to expanding my end-game PNC base :)

commented

Just tested this too and all the lag has gone around the pressure chamber and pneumatic processing plants. Thank you very much for fixing this and to everyone who helped track the cause down.

commented

Fixed in 2.8.1 release

commented

The symptoms you're describing suggest that some block or blocks are taking too long to rerender when the chunk has had a block update. Unfortunately, I've not encountered this problem, so it's rather difficult to debug...

If you're familiar with any Java profiling tools (e.g. VisualVM or JProfiler), it might be very useful to attach a profiler to the client process (not sure if you're playing on dedicated or an integrated SSP server), trigger some FPS drops, then check for methods taking up an unusual amount of CPU time.

Your JVM options look fine, and you have no issues with your hardware, for sure.

commented

I'm unfortunately not familiar with Java profiling tools (or Java programming in general) but I downloaded VisualVM and used MultiMC to attach it to the running java process. I loaded a singleplayer test world (Flat: Redstone Ready) and started placing sandstone blocks (via holding rightclick) next to a single uncooled advanced air compressor feeding into a 5x5 pressure chamber, using two redstone modules, a safety module, a pressure gauge and a regulator module to manage the flow of pressure.

Unfortunately I have zero indication of how to navigate the snapshot that was created during this profiling, but I managed to export it to this file if it is at all helpful (this is a .ZIP because Github's file uploader doesn't support the .nps file type):

pneumaticcraft-blockstate-lag.zip

commented

That might actually be quite helpful. It looks like the client is spending quite a lot of time recalculating pressure tube block shapes - they're hard to cache fully since a tube can have a bunch of different modules attached to each side, and that needs a bit of dynamic recalculation. I'll take a look though, and see if I can be a bit smarter about caching there.

commented

Thanks for taking the time to investigate. That would solve the pressure tube / modules problem, but I've experienced similar lag issues just with a single harvester drone breaking tree leaves (with 0 pressure tubes or charging pads around). This leads me to believe that pressure tubes are not the root cause of the problem, there seems to be something deeper than that affecting the performance.

commented

Yeah that's more likely to be a vanilla issue...

commented

I'm not sure if it is. I just tested vanilla, no performance issues. I also tested an automatic Quark cobble generator (uses a series of pistons with iron rods attached to break cobble made via vanilla cobble gen), and a Botania tree farm, and didn't experience any lag. This only seems to happen with PneumaticCraft, specifically in chunks where PneumaticCraft is doing its thing, and close to a chunk boundary. If I do some action 2 chunks away from a chunk with significant PNC activity, there's no lag at all.

EDIT: I just remembered off-thread terrain rendering and tried seting alwaysSetupTerrainOffThread in forge-client.toml and it definitely improved the pressure tube / advanced air compressor sitation. hardly any lag there. But it made the lag when drones are harvesting blocks even worse. X___X

Also, I just revisited your previous comment:

pressure tube block shapes - they're hard to cache fully since a tube can have a bunch of different modules attached to each side, and that needs a bit of dynamic recalculation

Have you considered adding a new tier of pressure tube that is lower than the basic one? So, it has no air capacity buffer at all, modules cannot be used on it, it doesn't check for logistics networks, or anything like that at all. It serves purely as a way to transport air, and that's it. It just checks that a pressure source at input A is connected to a pressure sink at output B and if valid, "teleports" the air from place to place (similar to how XNet cables work). That may make PNC more accessible to people on lower end machines, as those pipes could be used as a lag-free alternative to transport air.

commented

Okay, I've solved this, sort of. The issue was happening in singleplayer. I mostly play singleplayer because it's just easier and I usually play the game by myself, so no need for a server.

I decided to investigate running a server instance on the same PC that I play on. I set up a little server that runs off of my SSD while I play the game on my HDD. I connect to the server via localhost.

When doing that, the mod is butter smooth. I'll leave closing this up to your discretion.

commented

Interesting. I would expect a dedicated server to be smoother than an integrated server, even running on the same machine, but I'm surprised that the difference is that drastic.

Keeping this open for now, since I do plan to push some changes to make pressure tube shape calculation a lot more efficient...

commented

Have you considered adding a new tier of pressure tube that is lower than the basic one?

Probably wouldn't help, since the lag (in this case at least) is client side and related to shape calculations. The calculations to move air around are all server-side, and just involve some (relatively) cheap arithmetic.