-
-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(testbed): step at a fixed interval #144
base: master
Are you sure you want to change the base?
chore(testbed): step at a fixed interval #144
Conversation
Hmm this completely destroyed the perf of the keva tower demo, probably because each step takes more than 16ms 🤔 |
Could you please record a few seconds of performance log in chrome dev tools? Curious to what exactly is tanking the performance. |
Here is the profile Profile-20220621T200802.json.zip. This is what you were asking for right, or did you want screenshots? Looks like because the fixed update step will ALWAYS run it builds up a lot of work in 1 frame when |
Yes, that was what I wanted to look at. Not sure what is causing the so many steps to be executed in a single frame yet. One thing - this part should be outside of while loop, after it ended. We are probably interested in taking the snapshot of the current state, the intermediate steps won't be visible, as their states won't propagate to the renderer.
|
Thank you for this PR. However, I’m not sure that this is the actual cause of #92 and dimforge/rapier#345. I think these problems were related to the way our webworker was setup. So I believe that these issues are already fixed (I just didn’t upload the updated demos until now). |
Ah that could be the case! But I'm not 100% the demos are deterministic right now since Maybe a good enough solution is just to get the time delta in |
Determinism means that for the same number of physics steps, you get the exact same result. It is unrelated to the frequency at which you call In other words determinism doesn’t mean you get the same result after the same amount of real-world time. It means you get the same result after the same amount of physics-world time.
Setting the |
I think I get it. Would determinism break if the app drops some frames? E.g. some intensive is happening and fps drop from 60hz to 50 etc. How is it recommended to step in apps right now if you don't want simulations on 120hz screens to run faster than on 60hz? |
The app is free to drop any frame they want. All that matters is that at all times, the physics is stepped with the same inputs. The app can choose to step whenever they want (for example, it chooses not to call the physics stepping at all when you pause the simulation, this doesn’t break determinism).
To clarify my first comment on this thread: my intent was only to say that this PR isn’t really addressing #92 and dimforge/rapier#345. However, I do believe this PR is a good addition, because stepping the physics 60 times per real-world second (while keeping If the framerate is smaller than 60Hz (because running on a 30Hz monitor, or because the physics takes more than 0.016 seconds to compute), I suggest simply running the stepping only once per "slow" frame. Real games may want to do extrapolations or other strategies, but I don’t think it’s worth it for simple demos. In other words:
|
Gotcha! I see, makes sense. Updated the PR description. I updated the PR to work like you described (I think), but with the new approach I don't really know how to calculate the Side note, the new approach fixed the perf issues on the keva tower demo 🎉 |
Not sure I understand why, IMO it only makes sense to create a snapshot each time we've run |
be86fdf
to
e982ce5
Compare
@sebcrozet Made some more improvements and added the same logic to the 2d testbed, from my testing everything looks good but let me know if there is anything I've missed or you want me to change! |
Why
Ensure simulation runs at the same speed on different monitors (60hz/120hz etc)
Changes
world.step
at a fixed consistent rate (60hz)Loosely based on https://gafferongames.com/post/fix_your_timestep/