Skip to content
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

PhaseMachine Performance in Game Loops #46

Open
dsriseah opened this issue Dec 17, 2024 · 0 comments
Open

PhaseMachine Performance in Game Loops #46

dsriseah opened this issue Dec 17, 2024 · 0 comments

Comments

@dsriseah
Copy link
Owner

Currently, PhaseMachine has overhead in its invocation loops. Consider this example from an SNA app implementing a game loop:

async function Start() {
  const { frameRate, frameDurMS } = GSTATE.GetTimeState();
  const { RunPhaseGroup } = CLASS.PhaseMachine;
  // start
  await RunPhaseGroup('SNA_GAME/INIT');
  // loop
  GAME_TIMER = setInterval(async () => {
    if (frameRate > 0) {
      GSTATE.UpdateStateTimers();
      await RunPhaseGroup('SNA_GAME/LOOP_BEGIN');
      await RunPhaseGroup('SNA_GAME/LOOP_CALC');
      await RunPhaseGroup('SNA_GAME/LOOP_THINK');
      await RunPhaseGroup('SNA_GAME/LOOP_RENDER');
    }
  }, frameDurMS);
}

The game loop defined in the interval timers uses the static method RunPhaseGroup which has a couple of performance problems:

  • the string-based lookup runs through DecodeHookSelector to look-up the machine name, then invokes each phase in the group one-by-one
  • the invocation wraps the phase group execution in promises, which isn't desirable in a realtime game loop

It should be possible to write a dereferencing method that returns stacks of functions without the async-await default behavior, which could result in less overhead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant