anegostudios / VintageStory-Issues

Vintage Story's public issue tracker for reporting bugs, crashes and the like
41 stars 16 forks source link

Occasional Client Lag Spike #1202

Open zufar100 opened 2 years ago

zufar100 commented 2 years ago

Windows 10 v. 1.15.1 Nvidia 1050ti Intel i7-6700k No mods Double world height, all other settings default

When playing, I get an occasional lag spike on the client where the game freezes for a split second. I can be playing on the absolute minimum settings and it will still occur. I have tried reinstalling the game and changing Nvidia settings, but with no luck. I have had this issue since 1.13. I've been hoping it would resolve itself but it never has. There doesn't seem to be a pattern to it, other than it occurs about once a minute or more.

Here are some logs where it occurs. Let me know if there is any other information I can provide. It is a really frustrating issue, especially when I'm not able to tune it out.

Thank you.

19.7.2021 21:29:42 [Notification] A tick took 263.35ms rend3D-ret-op: 260.27ms beginrenderstage-Opaque: .47ms rend3D-ret-opnc: .39ms rend3D-ret-tpp: .19ms rend3D-ret-lp: .19ms rendTranspDone: .18ms entity-done-bh-repulseagents: .17ms ree-op-b: .14ms

19.7.2021 21:30:12 [Notification] A tick took 240.54ms rend3D-ret-op: 237.12ms beginrenderstage-Opaque: .49ms doneMTT: .47ms rend3D-ret-opnc: .39ms rend3D-ret-tpp: .31ms entity-controlledphysics-end: .25ms rend3D-ret-lp: .17ms ree-op-b: .17ms

19.7.2021 21:30:15 [Notification] A tick took 234.32ms rend3D-ret-op: 230.48ms beginrenderstage-Opaque: .74ms rend3D-ret-opnc: .47ms entity-controlledphysics-end: .41ms rend3D-ret-tpp: .34ms rend3D-ret-lp: .22ms doneMTT: .18ms ree-op-b: .15ms

radfast commented 2 years ago

Thanks for reporting. Some questions please:

1) Do you have the same issue when playing a map with a standard world height? We did a lot of performance tuning in 1.15 aiming to eliminate this type of problem finally, but our testing would have been with standard world heights so it's possible something is not optimised for a double world height.

2) Are you playing single player? You could try some of the tips mentioned here, specifically tip number 1.

3) Your debug logging shows the issue here is highly likely to be CPU-side, I mean it's in the C# / .NET code not in the GPU. One possibility is that this may be related to the garbage collector running some large operation, that would explain the occasional nature of this. There's no other reason I can think of why looking at the same scene, which the game can normally draw in less than 1/60 second, would sometimes take 250ms. Please could you try testing with the Ctrl+F3 debug overlay enabled, and keep an eye on the memory use in the top right corner. On the client, memory use should normally sit around 1800MB-3000MB, it slowly ramps upwards over time, in particular if you are moving around and causing new chunks to be loaded at the map borders. Client memory use can be less than that if you are playing on a server (including a server hosted on your own machine, see tip number 1 linked above). If you see memory use climb above 3000MB then collapse back by 1000MB or more, or similar, that is a sign the garbage collector did some heavy work that tick.

4) If - as I suspect - it is the garbage collector as discussed in (3) then you might be able to tweak it slightly by changing the Optimize RAM setting in Graphics Settings. I also normally recommend enabling Occlusion Culling in Graphics Settings, but you could try disabling that and see if it makes a difference.

Please let us know how you get on with the above.

If the above steps make no difference, it could be something outside Vintage Story causing this, including something in Windows or your graphics drivers. I would take a good hard look at all the background processes and startup applications you have on your system, especially anything which uses the HDD or the network, and ruthlessly close them down or block them from starting at all unless they are essential. Also, personally I often recommend OOSU10 which can be used to custom disable some of the potentially unwanted parts of Windows10 - please note this is a personal recommendation not an official endorsement by the VS team!

On my own PC I also disable the services named "Nvidia Container LS" and "nvwmi64.exe", though I do this mainly to make my computer use very low CPU and no HDD when idling, to extend battery life. Otherwise these two services keep a CPU core constantly active and regularly activate the HDD. That may be an issue with my particular Nvidia card which is different from yours, I don't know - YMMV!

radfast commented 2 years ago

Also: if you are spotting high RAM use (3000 MB or higher), please try pressing Alt+F8 at that point for some RAM usage debug info

zufar100 commented 2 years ago

Thank you for the quick reply!

1) yes, playing on a default height, or completely flat world I have the same issue.

2) I usually play multiplayer, but on single player it happens as well. When I first load the world (on singleplayer), it happens frequently and at consistent intervals, then over some time, it becomes sporadic and occurs less often. When on multiplayer, there doesn't seem to be any pattern, start up or otherwise

3) This is happening at all memory usage levels. The memory usage slowly climbs, and the lag spike happens occasionally during this entire process. It does not seem to have relation to the memory dropping back down again.

4) Any combination of ram optimization and occlusion culling does not seem to make any difference.

As an additional note, I don't have to be moving for the lag spikes to happen. It seems to occur the same if I am moving or not.

zufar100 commented 2 years ago

Also: if you are spotting high RAM use (3000 MB or higher), please try pressing Alt+F8 at that point for some RAM usage debug info

Where does this log to?

radfast commented 2 years ago
  1. This is happening at all memory usage levels. The memory usage slowly climbs, and the lag spike happens occasionally during this entire process. It does not seem to have relation to the memory dropping back down again.

This sounds to me like the issue might not be in Vintage Story. You could test in Windows with every non-essential service shut down? (To test this without changing your setup generally, try shutting down processes in Task Manager. There may be a few naughty ones that restart themselves, but you'll see that happening.)

One other thought, I guess it's also possible your CPU is thermal throttling itself heavily. See discussion here

zufar100 commented 2 years ago

My antivirus has been troublesome before, but disabling it didn't fix it unfortunately. I already keep most processes shut down on my computer, but I will see what I can do about limiting it more.

As far as temp goes, I don't think that is the issue. Running at 30 frames still incurred spikes, and all my hardware temps are under 65 C

zufar100 commented 2 years ago

Unfortunately, after stopping services, processes, and anything I could think of, it still has the lag spikes :(

radfast commented 2 years ago

OK this is very weird. I also have an i7, and an nVidia GPU less powerful than yours, and I don't have the issue...

I'll discuss with Tyron and see if we have any more thoughts on possible causes.

zufar100 commented 2 years ago

I appreciate it! Not sure if it changes anything, but I did install at a non default location as well

tyronx commented 2 years ago

When I look at these profiling results I see something very different than @radfast.

rend3D-ret-op is the piece of code that renders most of the terrain. It is usually not CPU bound nor RAM bound. Most of the time spent there is likely waiting for the graphics card to render or to accept the render call.

I would check the following:

zufar100 commented 2 years ago

Thank you for taking the time to look into this!

Did not work:

Maybe something:

However, this led me to discover that when I have the pause menu open, the lag spikes occur at a regular interval and much more frequently. This also led me to use the f4 key to remove my hud, but I still had the occasional lag spike when standing still or moving.

zufar100 commented 2 years ago

Some good and bad news on this issue:

Bad news: This is still a problem for me :/ I did another clean install and updated my nvidia drivers and it didn't change anything.

Good news: I usually play in fullscreen and this is where I get the occasional stuttering. If I change the game to windowed, and then back to fullscreen. It seems to go away. At the very least the stuttering is so small either my brain makes it up, or I can barely notice.

I hope this helps!

Harlekin13 commented 11 months ago

Similar problem here in 1.17.12 (but not in earlier versions).

I use basically the same settings and mods as in the versions before (with the exception of 1.16 which i played with massively reduced ratio of ingame time to real time), but since the hardware change (before i5-3570, 16GB RAM, now Ryzen5 5600G, 32GB RAM, unchanged Radeon RX580 OC 8GB GPU) after a few hours the memory usage reaches constant 20-30GB and the game starts stuttering with occasional extreme lag spikes (more short freezes).

It doesn't matter what i do ingame: i can run around exploring, loading new chunks, or afk with the game paused and it still will reach the point where any press of a button takes several seconds to register. It even seems exploring has less impact than staying in one area with occasionally pausing the game. It's neither the new CPU (utilized max around 12-15% while VS lags) nor the GPU (which is constantly stressed with the load of the game which hasn't changed). The game runs off an internal HDD, but with a basically portable installation (data and mods paths in the same directory), that too hasn't changed and the HDD is fine. Hence the memory hogging seems to be the only reasonable culprit. But VS seems to hog additional memory even while paused, which shouldn't happen.

tyronx commented 11 months ago

sounds to me like you have set 'optimize ram' to off - which is no longer possible in 1.18, due to the endless ram consumption that results from it

Harlekin13 commented 11 months ago

it was set on the default "optimize somewhat", i'll try "aggressively optimize ram". Would have set it higher from the beginning if not for the hint "may cause mild lag spikes when enabled. Thanks.

1 17 12 graphics settings 1 17 12 optimize ram hint

Update: The same lag spikes occur but after way under an hour already. Maybe the problem lies in that VS tries to optimize ram, but then it should have happened with only 16GB system memory too. Maybe it isn't advisable to give VS more than those 16GB to use? Maybe a fixed allocation (of idk 10GB similar to the recommended for modded MCJava) might mitigate the problem?

tyronx commented 11 months ago

do you have mods installed? Also make sure to update to the latest version of the game

C# Applications dont have such such allocation system as java does.

Harlekin13 commented 11 months ago

As i have written: i play modded 1.17.12. But the game setup didn't change between hardware changes, it's even still the same installation. All drivers are the most recent stable ones.

I don't plan to update to 1.18 before it is finalized and the mods i use (or will have to use instead) are updated too. I'm only around 300 hours in my current world and started going into steel (still haven't found ANY borax to make an iron anvil though) and each change of version i will start anew, because mods will likely have to change (because some always become abandoned and incompatible with the new version). As it seems the ram optimization is the reason for the crippling lag spikes not their solution and as you've written that it won't be able to be turned down or off, I suspect 1.18 to be a pure lag hell similar to the "aggressively optimize ram" setting, that i just tested, or at best the problem still being as it was with "optimize somewhat", that doesn't particularly motivate moving to the newer main version, which in addition seems to be known to break mods that weren't made explicitly for it. I don't look forward to having to comb through the mod database for weeks again, to tailor the game to my needs and wants, i just broke even in the ratio of playtime in the version versus time setting it up.

Opera GX is written in C# and has such a setting, obviously there has to be a way to do that. Though likewise obviously they have a bigger dev team and it's not fair to compare every dev to that, this argument only targets your generalized argument, that there wouldn't be such an allocation system for any C# application.