openfl / lime

A foundational Haxe framework for cross-platform development
https://lime.openfl.org/
MIT License
749 stars 359 forks source link

Limit total time spent on green threads. #1774

Closed player-03 closed 1 month ago

player-03 commented 3 months ago

Every single-threaded ThreadPool takes up a certain fraction of the app's time per frame. Without any coordination, they could take up more than 100% of available time, causing the app to slow down. By using static variables, we can make them work together to limit the total time spent per frame.

For instance, at 60 fps and a workLoad of 0.5, ThreadPools will work together to take up approximately 1/120 of a second each frame. This leaves another 1/120 for everything else on the main thread.

This also fixes a null pointer error by waiting to access Window.frameRate until a window is actually available.

player-03 commented 1 month ago

@jgranick This PR should in theory fix the crash(es) you were seeing. Can you confirm?