Skip to content

Conversation

b4rtaz
Copy link
Contributor

@b4rtaz b4rtaz commented Oct 19, 2022

This commit increases the frame loop performance by 15-20%. How I tested it? I've turned on CPU throttling 6x in Chrome and I've run the below code.

const results = new Array(30);
let pos = 0;

function onAnimationFrame() {
   const start = Date.now();
   nes.frame();
   const end = Date.now();
   results[pos] = end - start;
   pos = (pos + 1) % results.length;
   if (pos === 0) {
      const avg = results.reduce((a, b) => a + b, 0) / results.length;
      console.log(avg);
   }
   // ...
}

This improvement is felt well on slow phones.

Results

Before my change:

Screenshot 2022-10-19 at 23 49 22

After my change:

Screenshot 2022-10-19 at 23 48 42

Copy link
Contributor

@ZhaoTonggang ZhaoTonggang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried your modification and the experience was great!

@bfirsh
Copy link
Owner

bfirsh commented Jul 27, 2025

Thank you for the contribution!

@bfirsh bfirsh merged commit 81bafff into bfirsh:master Jul 27, 2025
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

Successfully merging this pull request may close these issues.

3 participants