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

Improve frame loop performance by 15-20% #436

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

b4rtaz
Copy link

@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

@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!

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.

None yet

2 participants