Claw

FPS and Physics Timesteps

Recommended Posts

This question has come up a couple times recently, and after some discussions, I've realized people still aren't sure about the concept of FPS and Physics Timesteps in KSP. KSP is physics bound, and will be for quite some time (if not always). Plus, with 1.1 looming around the corner, now might be a good time to discuss FPS and physics, since 1.1 will definitely have an impact on performance. Additionally, people may misinterpret low FPS in KSP as (by itself) an indicator of poor performance. While FPS and physics are linked, KSP offers a somewhat unique tweak that most games don't have, the "Max Physics Time-Delta per Frame" option (which I'll call Time-Delta). That Time-Delta slider will be the "TLDR" outcome of this explanation, but it'll take a moment to get there...and I know how this forum likes details, so here we go.

Historically, the Time-Delta tweak has been understood that "lower is better, drive that thing down to the lowest value (0.03) so that your ship doesn't fall apart." However, that's not exactly true. The Time-Delta setting has no impact on the physics timestep. It will have an impact on visible game performance, but not the physics timestep itself.

 

In order to understand what it's really doing, it's important to understand that KSP runs gameplay frames and physics frames. (Probably most Unity based games do, but KSP is especially physics hungry.)

  • Gameplay Frames: Where all the overhead of running the game occurs, such as checking user input and building graphics frames.
  • Physics Frames: Where all the internal interactive parts of the game occur, which includes things like calculating engine thrust, wing lift, aerodynamic drag, and all the rigid body (classic physics) interaction that goes with it.

 

The two actual measures of performance for KSP that the user sees:

  • Frames Per Second (FPS): Most people latch onto FPS as the measure of performance for traditional reasons. Many first and third person perspective games have direct linkages of FPS to gameplay speed. If the FPS is really low, the game itself also runs quite slowly. Gameplay speed (things moving, monsters shooting, etc...) is directly linked to the ability of the game to pump out frames. FPS isn't directly shown in KSP, but people seem ever in search of an FPS indicator.
  • Real Time per Gameplay Time (Seconds per Universal Time) - KSP's performance is highly bound by physics. Game-time passes in the form of Universal Time (UT) and is often visible as that little green and/or yellow (hopefully not red) blinky time stamp in the upper left corner. There's no direct measure of how many real seconds of time is passing for each second of UT, but KSP's physics performance is tied to this statistic.

 

Maximum Performance:

  • In KSP, FPS maxes out at 60 frames per second (or whatever you have your max set to, but lets use 60 for discussion). This means that the gameplay frames happen 60 times per second. It's important to note that this isn't tied to physics calculations, which is (again) the bottle neck in KSP.
  • Seconds/UT can never be less than 1 when running at 1x timewarp (i.e. can't be less than one second of real time to do one second of game time). The physics timestep is fixed at 20 milliseconds (ms). So, if I'm doing the math right, that means that there are 50 physics frames per second.
  • So together, at maximum performance, there are 60 gameplay frames, and 50 physics frames running every second in KSP...

 

What happens during lag? -- When the game starts to lag, both the FPS and Seconds/UT start to suffer.

  • FPS - FPS starts to decrease, and the user sees this directly. The game starts to take longer to display each frame, and the game begins to look like a flip-book or slideshow. It also may become less responsive to input, unless the user is holding down keys.
  • Seconds/UT - The Physics Timestep never changes, it's always 20ms. That means that when things start slowing down, the Seconds/UT goes up (more real-life seconds pass for every second of game time).There are less physics frames being calculated each second, so it physically takes longer for your ship to go some fixed distance. If it takes 2 seconds of real time for every 1 second of UT, then physics is only running 25 frames per second, instead of the maximum 50.

 

But Claw, you told me FPS and physics are not interlinked, but it sure sounds like they are.

  • I didn't say they aren't interlinked, just that FPS is not the sole measure of performance in KSP (though it seems to be the one many people focus on). They are, in fact, interlinked directly through that Time-Delta slider that I mentioned in the beginning. 

 

So then what is "Max Physics Time-Delta per Frame"?

  • It's the user's way of saying, "I'm willing to let X amount of physics time to pass for each gameplay frame." The user is directly trading off gameplay frames for physics frames, but only when physics can't run at 50 physics frames per second (i.e. more than 1 second passing for each gameplay second, or higher than 1.0 Sec/UT).
  • So, at the default setting of 0.04, the Time-Delta indicates that "I'm only willing to let 0.04 physics seconds pass for each frame that I see." Or, up to 2 physics frames per gameplay frame.

 

What?

  • So at the default Time-Delta setting (0.04), if a ship is getting 15 FPS (out of a max of 60 FPS), it is still calculating 30 physics frames per second (out of a max of 50). So running at 25% of the FPS is still giving 60% of the physics speed, and 1.67 Sec/UT.
  • If FPS was the direct measure of performance, 15 FPS would result in running at 4 sec/UT.

 

So what does that mean for the slider? (Here's your TLDR.) The player has a bit of a choice of how much FPS to sacrifice for physics (and game time) to progress "normally."

  • A higher Time-Delta setting, say 0.12, means that you're willing to let the computer spend more of it's time calculating physics than at a setting of 0.04. Up to 6 physics frames (at 0.12) can pass instead of 2 (at 0.04). When the computer can't keep up with doing 50 physics frame calculations per second, it will start to sacrifice visual frames. At worst, it will only show 8.3 FPS (slider at 0.12) before starting to sacrifice physics speed. So in this instance, while the game will only give 8.3 FPS, it'll still be running at 1 Sec/UT, or "real-time" physics...pumping out 50 physics frames per second.
  • It's  important to note that this isn't a 1 for 1 trade. The game isn't converting 10 gameplay frames into 10 physics frames, just that it's spending less time doing the gameplay frames in favor of the physics frames.

 

This is why FPS isn't the pure measure of performance in KSP. -- Indicator? Yes. Only source? No.

It's entirely possible to have low FPS, but still get your ship into orbit in the same amount of real-life time as someone with a "beefier" computer who gets to see a less "choppy" version.

Edited by Claw

Share this post


Link to post
Share on other sites

I want Ksp to have the beamng drive time system because I want the game slowing down only when I want it even if I'm getting 2 fps but when I want to get good frames I slow the game down like 16x or whatever. Also useful for crashes.

Share this post


Link to post
Share on other sites
58 minutes ago, Claw said:

since 1.1 will definitely have an impact on performance. 

Thanks of the info, as a veteran player I knew all the above already. What pricks my ears is your quote above. You seem to be preparing us for something.. Do you know something we don't about 1.1 performance?

Share this post


Link to post
Share on other sites
1 minute ago, Majorjim said:

Do you know something we don't about 1.1 performance?

 

It's not exactly a tell tale of anything. Every update has an impact on performance. Consider, for example, the impact to 1.0 and it's overhauled aero and thermo.

But really, at the moment, I'm more interested in dispelling the myth that KSP's measure of performance is rooted in FPS. I've seen this question of FPS come up several times lately as 1.1 approaches, and I was actually surprised at the number of veteran players who still misunderstand the slider. As you're aware, KSP performance is much more complex than what FPS portrays. Seeing statements such as "doing XXX doubled my FPS" doesn't necessarily mean that it's double the physics performance. It might look like better performance, but I wanted people to be aware of what actual performance they are getting...so that they make their choices with proper information.

Share this post


Link to post
Share on other sites
Just now, Claw said:

 

It's not exactly a tell tale of anything. Every update has an impact on performance. Consider, for example, the impact to 1.0 and it's overhauled aero and thermo.

 

OK I understood the idea behind the post, it is important but as above you compared the 1.1 release to the 1.0 release impact and as we know version 1.0 took quite a significant dive in terms of performance.. Now I am really worried!

 I truly hops this isn't you being asked by Squad to prepare us for even worse performance man, say it ain't so!

 

Edited by Majorjim

Share this post


Link to post
Share on other sites
Just now, Majorjim said:

 I truly hops this isn't you being asked by Squad to prepare us for even worse performance man, say it ain't so!

Please try not to infer meaning where I intend none (it's tempting, I know). My aim really is (as I've done as a community member in the past) to explain what some of these esoteric things are, and how they impact the game.

Like I said...I was surprised at some of the folks I know directly who have played for a long time and misunderstand how all this ties together. I was guilty of the same thing once upon a time, so I thought I'd share the knowledge. :)

Share this post


Link to post
Share on other sites

I think there might be a small typographical error.  When defining the seconds/UT at maximum performance you say (bold emphasis mine):

2 hours ago, Claw said:

Seconds/UT can never be more than 1 when running at 1x timewarp.

Shouldn't that be "Seconds/UT can never be less than 1"? Because a couple bullet points down you say:

2 hours ago, Claw said:

That means that when things start slowing down, the Seconds/UT goes up

And then:

3 hours ago, Claw said:

(i.e. more than 1 second passing for each gameplay second, or higher than 1.0 Sec/UT).

And then you give a specific example:

3 hours ago, Claw said:

So at the default Time-Delta setting (0.04), if a ship is getting 15 FPS (out of a max of 60 FPS), it is still calculating 30 physics frames per second (out of a max of 50). So running at 25% of the FPS is still giving 60% of the physics speed, and 1.67 Sec/UT.

I could be wrong, and completely misunderstand something, but I thought I'd say something just in case.

 

I also have a quick question.  When you say that the physics timestep is locked in to 20 milliseconds, is that counted by the UT (game) clock or by the real world clock?

Share this post


Link to post
Share on other sites
10 minutes ago, FullMetalMachinist said:

Shouldn't that be "Seconds/UT can never be less than 1"?

Yes, that was a typo (now corrected and annotated). Thanks :)

 

10 minutes ago, FullMetalMachinist said:

When you say that the physics timestep is locked in to 20 milliseconds, is that counted by the UT (game) clock or by the real world clock?

The short answer is that it's locked to UT. 1 UT second is always 50 physics frames because each physics frame is locked to 20ms of game time (UT). The game tries to keep 20ms in UT equal to 20ms of real-time, but when craft get large and things get laggy, that "real time to UT" relationship starts to break down (hence the Seconds/UT). Real-time continues at it's normal rate, but UT slows down because it takes longer for the game to do all the math required to calculate the physics change of that 20ms step. In other words, it's physically taking more than 20ms of real time to calculate the 20ms of physics changes in-game. The game never increases the physics step size to "catch up" to real-time.

Edited by Claw

Share this post


Link to post
Share on other sites
1 minute ago, Claw said:

Real-time continues at it's normal rate

I had no idea! :P 

On a serious note, thanks for taking the time to explain all this, I think I actually understand now.

Share this post


Link to post
Share on other sites

what happens in physics-warp?
 does it increas physics timestep? or try to calc it faster?

I think it start increase physics timestep from 3x because there is warning massage shows (2x doesn't)

Share this post


Link to post
Share on other sites
Just now, Claw said:

Please try not to infer meaning where I intend none

That is all you had to say.

  It was as US cops call a 'hunch'. I trust my 'hunches'. Time will tell.

Just now, omelaw said:

what happens in physics-warp?
 does it increas physics timestep? or try to calc it faster?

I think it start increase physics timestep from 3x because there is warning massage shows (2x doesn't)

After 4x physics is 'off' and the craft is on 'rails'.

Share this post


Link to post
Share on other sites
20 minutes ago, omelaw said:

what happens in physics-warp?
 does it increas physics timestep? or try to calc it faster?

I think it start increase physics timestep from 3x because there is warning massage shows (2x doesn't)

No, all levels of physics warp increase the physics timestep.  It only warns at 3x and 4x because a physics step of 40ms (at 2x) doesn't (usually) cause any issues for the vessel but going up to 60 or 80 ms is much more likely to.

Share this post


Link to post
Share on other sites
24 minutes ago, omelaw said:

does it increas physics timestep?

Yep, this one. Phys warp increases the timestep used in physics calculations, for all levels (2x to 4x). (ninja Padishar)

Edited by Claw

Share this post


Link to post
Share on other sites

I thought I understood the concept, but now I'm just more confused.

 

So if I want to see more Frames per Second (Gameplay frames), and "don't care" about how fast or accurate physics are, do I set the Max Physics Time-Delta per Frame to a higher value, or to a lower value?

Edited by Kobymaru

Share this post


Link to post
Share on other sites
2 hours ago, Kobymaru said:

I thought I understood the concept, but now I'm just more confused.

 

So if I want to see more Frames per Second (Gameplay frames), and "don't care" about how fast or accurate physics are, do I set the Max Physics Time-Delta per Frame to a higher value, or to a lower value?

then lower the PTD would be better.

 

Share this post


Link to post
Share on other sites

I have an older machine, and I've at times hacked the settings file to set max fps to 30- is this pointless, or will it help with performance a bit?

Share this post


Link to post
Share on other sites
4 hours ago, Kobymaru said:

So if I want to see more Frames per Second (Gameplay frames), and "don't care" about how fast or accurate physics are, do I set the Max Physics Time-Delta per Frame to a higher value, or to a lower value?

First (so that it's not confused) the accuracy of physics are not at stake when using the Time-Delta per Frame slider (that's a main point of my writing the original post). Moving the slider around does not change any of the math during a physics frame.

If you want more FPS, then generally set the slider lower. 0.04 is the default, which gives a minimum of 1 graphic frame per every 2 physics frames. You are telling the game that you would rather do fewer physics calculations per second in favor of keeping the FPS up. However, setting the slider to 0.04 does not guarantee a set FPS, because the game will still only show graphic changes after it's been able to calculate at least two physics frames. So if it takes a full second to calculate two physics frames, then you would still only end up with 1 FPS.

 

Maybe another way to think of it is as if you're telling the computer:

  • A low slider value (0.04) means "Keep the FPS up, even if that means you have to slow game time progression."
  • A higher slider value (0.12) means "If you start having any problems keeping up with physics, ignore FPS."

 

With a high slider value (0.12) it's entirely possible to get to orbit with a big ship at 9 FPS in the same amount of real-life time as a smaller ship that's running at 60 FPS.

 

27 minutes ago, Tantalus said:

Thanks a lot for explaining all this.

My pleasure. Hopefully it'll help some folks out. :)

 

 

18 minutes ago, Waxing_Kibbous said:

at times hacked the settings file to set max fps to 30-

It's pointless from the standpoint that you're not necessarily helping KSP out for physics, since (to some extent) KSP already dumps FPS in favor of physics. The default slider set to 0.04 means that physics will not start to "slow down" until the FPS goes down to 25 FPS.

It can, however, help in the sense that when KSP does start to slow the FPS down, you won't really notice it as much. Sometimes when people go from 60 FPS to 25 FPS quickly, it's more jarring than if you're already used to seeing 30 FPS, and then it slows down to 25 FPS. So it's a bit of a personal perception thing.

The other thing it can help with, is when you do have spare CPU/GPU capacity, you're not letting KSP constantly use it up. Which can mean an overall cooler running computer (since it's not working at full capacity all the time). This can be handy for older computers who might not have as good of cooling capability as they used to...or on a laptop if you want to try to save some battery life (and you're happy with 30 FPS).

Share this post


Link to post
Share on other sites

Most of this conversation seems (understandably) geared towards when KSP is struggling. But what happens when it can happily run physics calculations faster than 20 milliseconds? I get that that's where you come up against "the seconds/UT can't be less than 1", but what actually happens? If physics cals only take 10 milliseconds, what does the game do for the remaining 10 until it's time to calculate another physics timestep? 

Share this post


Link to post
Share on other sites
11 minutes ago, FullMetalMachinist said:

If physics cals only take 10 milliseconds, what does the game do for the remaining 10 until it's time to calculate another physics timestep? 

I'm sure it is running its own instance of KSP :sticktongue:

Ok to be serious, it does what any other program does, goin to idle state and leave system resources free for other tasks.

 

Share this post


Link to post
Share on other sites
32 minutes ago, Tantalus said:

Ok to be serious, it does what any other program does, goin to idle state and leave system resources free for other tasks.

Not exactly, the main Unity game loop is quite complex (apparently too complex even for the Unity documentation to describe accurately) and the interaction between the different types of frames and the framerate limiting and/or vsync is also complex but it basically goes round in a loop doing gameplay frames (user input, rendering and anything else that happens during gameplay frames) as fast as your settings (and computer) allow it to.

Share this post


Link to post
Share on other sites

In addition to what Padishar said...if it only takes 10ms to calculate the 20ms timestep, KSP does not move to the next physics frame because then (at 1x warp) game time would be happening faster than real time, and it's no longer 1x warp.

Share this post


Link to post
Share on other sites

anothrer question: does SAS control acts every physics frame or every gameplay frame?

and I think fps in debug screen is frame per in-game-second

Share this post


Link to post
Share on other sites
9 hours ago, omelaw said:

does SAS control acts every physics frame or every gameplay frame

Every gameplay frame.

 

9 hours ago, omelaw said:

I think fps in debug screen is frame per in-game-second

I'm not sure off hand, I'd have to go look. If so, then it's handy in a certain way, but probably not useful for most people.

Share this post


Link to post
Share on other sites

I'm trying hard to understand it :) but....

The physics step (and therefore physics frame & physics FPS) is fixed (even if it can complete faster it'll wait), 20ms or 50FPS. Any gameplay FPS above 50 leads to gameplay frames with no physics? Nothing moves for that gameplay frame? Is there any benefit to being above 50 gameplay FPS? It seems bad to be at 50 gameplay fps, the monitor is most likely 60Hz, it'll repeat frames, and bad to be above 50 gameplay FPS, the physics can't keep up and frames won't have it.

Share this post


Link to post
Share on other sites
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.