Jump to content

Frame rate drops after returning from map view.


Recommended Posts

Hi,

I've found a reproducible bug in KSP:

[KSP Version]: 1.10.1.2939 (WindowsPlayer x64) (x64) en-us 

The gist of it is that the frame rate drops after the first time that you look at the map within a flight and then return to looking at your ship. The drop in frame rate is proportional to the number of Kerbals on board. The drop in frame rate is not present (or less obvious) when you switch to IVA by pressing 'c', or go to the tracking station and then go to the flight again from there. However, the tracking station method will only restore a good framerate until you look at the map again.

 

How to reproduce.

Case 1 (on the pad)

1) Create a ship that can carry ~100 Kerbals. There is one called 'Test Craft' in the save file that works: https://drive.google.com/file/d/1mIRcbIYzVliJr1SRlM4hSECe01LSZIkE/view?usp=sharing

2) Fill the ship with 100 Kerbals.
3) Take the ship to the launch pad but DO NOT open the map. Wait for everything to load in, and try rotating the camera, moving the dials etc. Everything will be pretty responsive. (Great job optimizing the engine, SQUAD!)
4) Open the map by pressing 'm'. There will be a tiny bit of lag while it loads, but then the map will move smoothly afterwards.

5) Close the map again by pressing 'm'. You will be back at your ship, but everything will now be super laggy.

Case 2 (In Flight)

1) Create a ship that can carry ~100 Kerbals. There is one called 'Test Craft' in the save file that works: https://drive.google.com/file/d/1mIRcbIYzVliJr1SRlM4hSECe01LSZIkE/view?usp=sharing

2) Fill the ship with 100 Kerbals.
3) Take the ship to the launch pad but DO NOT open the map. Wait for everything to load in, and try rotating the camera, moving the dials etc. Everything will be pretty responsive. (Great job optimizing the engine, SQUAD!)

4) Launch the ship. Put it into max physics time acceleration and keep it going until you are in space. Everything should be pretty smooth when you use the controls, or rotate the camera. Notice that turning the cutaway view of the kerbals has no real effect on performance.

4) Open the map by pressing 'm'. There will be a tiny bit of lag while it loads, but then the map will move smoothly afterwards.

5) Close the map again by pressing 'm'. You will be back at your ship, but everything will now be super laggy.

6) Hit 'c' to go into IVA. Everything will become very responsive again. You can even run the game 4x physics accelerated without any lag. Try firing the engines, or rotating the ship to feel the massive difference.

7) Hit 'c' again to exit IVA. Everything will be super laggy again.

8) Hit 'esc' and select the tracking station. In the tracking station, select the currently active flight, and go to it. The lag will once again be gone.

9) Enter and exit the map to see that the lag is once again back.

Case 3 (Only 1 kerbal in flight)

1) Repeat the steps from Case 2, but this time have only 1 Kerbal in the ship. Notice that there is no perceptible lag at any point. i.e. It is strongly tied to the number of Kerbals on board.

 

Other relevant details.

1) I created a new standalone install to test this with a clean save file after I observed it in my main install. No mods were ever used on this install.

2) I used the default graphics settings by hitting the 'Reset Settings' Button in the settings window. i.e. 1280 x 720, running in a window.

3) My machine is an Intel Xeon E5-1650 v3 @ 3.5GHz (6 cores 12 threads) with 128GB ram and an Nvidia GTX1080 w/ 8GB of vram. Neither the CPU or the Graphics card were pushed even to 50% while running any of these experiments according to the charts in Task Manager.

4) Hitting the 'Fill' button to load the ship with 100 Kerbals freezes the game for minutes i.e. several seconds per Kerbal. I suspect some sort of n^2 or n^3 algorithm in there making things slow. I would love it if this was faster :).

Closing thoughts

A feedback that might happen with this bug report is to just not fly with 100 Kerbals, so I wanted to comment on that:
1) Building large crafts and flying with 100 Kerbals is super fun! (Until I look at the map) The game engine can clearly run with hundreds of Kerbals and parts aside from this bug and it would be awesome to take advantage of that.
2) Choosing 100 Kerbals was helpful when reproducing the bug, but the lag is still there with smaller numbers of Kerbals, just less severe. It would be better if it was not there at all.

3) Because the game runs fast in IVA, it feels like going into the map for the first time flips some internal flag that makes the game run slow from that point forward unless it is in map mode or IVA. If it really turns out to be that simple, it would be great to just turn that flag off again when you leave map mode. i.e. the simulation is clearly able to handle 100 Kerbals easily, it handles all the rendering and physics just fine until going into the map somehow changes the state.
4)  Thanks for making the amazing game that made me want to file this bug report!

 

Thank You!!!

 

Link to comment
Share on other sites

No offence, but...

since the game can handle a ship with 100 Kerbals that is extremely impressive by itself.

The minor downside to be a switch map lag and even fixable by going to tracking station and back should justify EVERY REASON NOT to submit that bug report.

For a game to handle something so big and not call the Kraken is by itself commendable.

Anyways.

Edited by Boyster
Link to comment
Share on other sites

Hi Boyster,

I agree with you premise. However, it's not a switch map lag, if I'm using the right terminology. I 100% wouldn't have filed a bug about that.

The issue is that after you look at the map, and then go back to looking at the spaceship, you suffer severe lag continuously. To the point where the ship is completely unflyable. i.e.

1) Fly ship with 100 Kerbals, everything is great. Awesome job with the optimizations!
2) Look at map... things look great, map is smooth
3) Look back at ship. Everything unbelievably laggy continously. Ship not flyable.
4) Go into IVA, lag is gone. Even physics acceleration possible.
5) Look at ship from outside again: horrible unflyable lag.
6) Go to tracking station, and back to ship, lag is gone from external view of the ship!
7) look at the map and back at the ship: lag is back.

The physics engine can clearly fly the ship with that many kerbals, even at 4x. Its amazing what they did. But something gets flipped when you look at the map, and stays flipped when you are no longer looking at it. i.e. the ship is non-flyable after looking at the the map.

It kind of like you have a Bugatti Veyron that engages the handbrake when you look at the GPS and refuses to release it unless you exit the vehicle. It feels like there is a bug there. 

When I saw that going to IVA alleviated the stutter, I thought "wow, to fix this, they probably have to look at the code that they execute when they go to IVA, and paste one of those lines over into the code that runs when you leave map view. That's a really low hanging fruit as far as performance optimizations go. I've got to let them know!" Its probably not that simple. But I can dream right?

The other thing to mention is that the issue still happens, but in a less showstopping way with smaller numbers of Kerbals. 100 Kerbals is unflyable after looking at the map, 20-30 is laggy but flyable. Even at 10, you might notice a micro-stutter. The game could be that much smoother for everyone if this is fixed, especially for those with space stations.

Does that make sense?

Edited by Alex55
Added note that you don't need 100 kerbals to experience effects of this bug.
Link to comment
Share on other sites

23 minutes ago, Alex55 said:

Hi Boyster,

I agree with you premise. However, it's not a switch map lag, if I'm using the right terminology. I 100% wouldn't have filed a bug about that
Does that make sense?

You were perfectly clear from the first post but obviously i failed to make my point.

I was talking about the simple fix you discovered to combat the fps drops.

I still stand by my opinion, they are far more urgent bugs and this one doesnt seem to be a simple fix or even worthy to be a bug report.

Its an extreme state of the game, like overclocking your pc, you even have a simple way to combat the clunkiness.

Do you see when you close the map that it loads down right all the IVA Kerbals, for a moment there is grey stutter and then they load.

I am gonna take a wild guess and say than when you close the map it loads 100 Kerbals IVA assets, again...it double loads them and it just cant handle it.

Or something close to that.

Edited by Boyster
Link to comment
Share on other sites

3 hours ago, Boyster said:

No offence, but...

since the game can handle a ship with 100 Kerbals that is extremely impressive by itself.

The minor downside to be a switch map lag and even fixable by going to tracking station and back should justify EVERY REASON NOT to submit that bug report.

For a game to handle something so big and not call the Kraken is by itself commendable.

Anyways.

I dont get how having many kerbals in a ship would slow down the game that much. Parts contribute mass, colliders and drag to the game that taxes the physics engine and understandably makes the game run slower. But aren't Kerbals just a number until you go EVA? What difference is there between a Kerbal inside a vessel and one unit of lets say liquid fuel?

Now 100 kerbals all on an simultaneous EVA causing lag is very understandable to me, but what makes 100 kerbals unloaded Kerbals do to cause performance issues that 100 units of liquid fuel doesn't? 

Link to comment
Share on other sites

32 minutes ago, Cattette said:

I dont get how having many kerbals in a ship would slow down the game that much. Parts contribute mass, colliders and drag to the game that taxes the physics engine and understandably makes the game run slower. But aren't Kerbals just a number until you go EVA? What difference is there between a Kerbal inside a vessel and one unit of lets say liquid fuel?

Now 100 kerbals all on an simultaneous EVA causing lag is very understandable to me, but what makes 100 kerbals unloaded Kerbals do to cause performance issues that 100 units of liquid fuel doesn't? 

Again just a guess but probably the loading and displaying the 100 IVA avatar images/video at the bottom right.

Link to comment
Share on other sites

7 hours ago, Boyster said:

Again just a guess but probably the loading and displaying the 100 IVA avatar images/video at the bottom right.

Hmm. Thats a good thought. I just tried that at the launch pad.

I clicked through all the avatars on the lower right. As I went to the right, there was static for each one at first, but then as I went to the left again, there was no static. At no point was there any lag as a result of loading the avatars. However, if they are being double loaded as you suggest, that could make a difference.

RE: difficulty of fix. Only squad / private division would know how hard it is to actually do, but this was my thought process: Squad spent a lot of effort optimizing recent versions of KSP. They made complex changes like changing the way the physics was being calculated, and reducing the number of objects they were creating and destroying to make things run faster. That would have required big rewrites. In this case, the engine works great already. It's just one if statement or two toggled into the wrong state after coming back from the map (I hope). Fixing it would at least quadruple the number of Kerbals comfortably in flight.

I don't think it is a coincidence that the lag doesn't exist when you first start using the ship. I suspect Squad actually did load testing on the Pad to optimize it.

My hunch is that the game uses an event loop internally, b/c it is built using Unity. Unity spools through all the events in that loop every frame (possibly multiple times). When you look at the map, a few events are added to the loop, and unity proceeds to try and execute them every frame, whether the map is loaded or not. When you enter into IVA, the code that switches to IVA removes the events and things run smooth again. When you exit, they are added back on, etc. Whatever those events are, we already know that the game doesn't need them for the simulation because it runs much better without them in the time before you look at the map. This is probably just a case where the wrong flag was left on after switching away from the map.

Fixing this would let some people use larger ships/stations, but it would also let people running on laptops have a more playable game experience with fewer Kerbals.

I would be really really grateful if Squad / Private Division took a look to see what the cause was.



 




 

Link to comment
Share on other sites

On 10/11/2020 at 8:21 PM, Alex55 said:

 

Hi,

I've found a reproducible bug in KSP:

[KSP Version]: 1.10.1.2939 (WindowsPlayer x64) (x64) en-us 

The gist of it is that the frame rate drops after the first time that you look at the map within a flight and then return to looking at your ship. The drop in frame rate is proportional to the number of Kerbals on board. The drop in frame rate is not present (or less obvious) when you switch to IVA by pressing 'c', or go to the tracking station and then go to the flight again from there. However, the tracking station method will only restore a good framerate until you look at the map again.

 

Have you files a bug report?

Link to comment
Share on other sites

There is a recent description of something very similar on the bug tracker (link) but not a real bug report.  I'll mention the very good report in the OP on that bug-tracker item.

Version 1.7.3 does not show the problem, but I agree that version 1.10.1 obviously does. 

Someone else noticed it and revived a very old thread (link).   The module-manager patch in that thread ( @PART[*]:HAS[@INTERNAL[*]] {!INTERNAL,* {}} ) solves the low frame-rate for me but of course also removes all views of the inside of the craft (all IVA views).

Another workaround is, each time after returning from map view, to EVA a Kerbal and reboard him, or switch to some other craft-or-kerbal in the same physics bubble, then back to the problematic craft.

I notice that memory use goes quickly to 98%, which makes me suspect the method of IVA rendering is over-using garbage-collected memory.

Link to comment
Share on other sites

  • 4 weeks later...
This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...