PistonDevelopers / Piston-Tutorials

Tutorials for Piston
545 stars 89 forks source link

Spinning square demo stutters on Windows 10 #234

Open ninjasource opened 4 years ago

ninjasource commented 4 years ago

Hi, thanks for your great demo. I recorded the spinning square using a high framerate video camera (I used my phone at 240fps) and noticed that there is a brief pause every 10 frames or so. At normal speeds this manifests itself as a slightly jerky rotation. This happens on both low and high DPI screens but it is more obvious on high DPI screens because the square is sharper. I have a decent graphics card and cpu. Has anyone else noticed this?

bvssvni commented 4 years ago

Did you run in release mode? Debug mode in Rust can be slow.

ninjasource commented 4 years ago

Unfortunately it happens on release builds too. I also checked and nothing else (of significance) was running on my machine at the time.

Some more information: When I run the release build exe from the command line directly (no cargo) it consumes 0-0.1% CPU on task manager and 30MB memory. CPU: i7-6700K 4 core at 4GHZ in High performance plan 32GB Ram NVidia GeForce GTX 1070 Windows 10 Enterprise 2016 LTSB

Same thing happens on the following machine (although it happens every 6 or so frames): Intel Nuc i7-8559U 4 cores @ 2.7GHz with built in Intel graphics Windows 10 Enterprise 2019

Lastly, it does not appear to happen on Ubuntu on a somewhat aging laptop of mine so I assume that this is a Windows only issue.

Setting the process priority to High or even Realtime makes no difference in Windows so this may not be related to process context switching.

bvssvni commented 4 years ago

Perhaps you could detect this spike by logging idle time:

The idle event is emitted before going to sleep, so if the game loop works harder at irregular intervals, it might have less time to idle.

bvssvni commented 4 years ago

This might be caused by varying update vs rendering. Using extrapolated time at rendering might fix the problem.

ninjasource commented 4 years ago

Hi bvssvni,

Thank you for your comments. I have tried quite a few things now and it appears as if there is jitter on the events.next() function which is apparent when you log an entry to the console every iteration. Sometimes the latency is more than a frame so I guess what I am seeing are dropped frames rather than a badly timed rotation function. There is quite a lot of variation in IdleArgs in the IdleEvent and I periodically get two idle events before an UpdateEvent. I don't really know what that means though. I am a little out of my depth here as I am not a graphics or game developer so I don't know how much help I can really be. If I log to the console in a simple 10ms delay loop on another thread I don't get any jitter so at least windows is not freezing the entire process periodically. Feel free to close this issue if you like as I doubt that I will be able to solve it.

Regards, David