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

Consider using setImmediate instead of setTimeout in the render loop? #9

Closed
eugeniopacceli opened this issue Nov 2, 2019 · 1 comment

Comments

@eugeniopacceli
Copy link

eugeniopacceli commented Nov 2, 2019

Hello!

This is a very cool project and also an impressive job!

I've been tinkering with the source code a little and I've noticed that in the render loop using Node's function setImmediate to set up the next iteration really outperforms setTimeout in my text environment (Node.js 13.0.1).

The line I'm referring to is index.ts:79, instead of

setTimeout(() => loop())

I've

setImmediate(() => loop())

or

setImmediate(loop)

with a substantial performance increase (on 120x28 the demo went from avg. ~65fps to ~250fps, on 237x70 it went from avg. ~30 fps to ~64 fps).

Functions set to run by setImmediate respect I/O events and their callbacks like setTimeout ones do. In this implementation it allows for the event handler that changes the rendering scene resolution to run on terminal window size change just like setTimeout.

Other tests I did were with a while(1) inside the loop function, converting the loop function to an async function and having it's callback call it again, and having the next iteration of the function set up to run with process.nextTick. All of those are also faster than setTimeout, but they seem to hang the process on the loop and disallow other event handlers and callbacks to run.

Is there a reason for why setImmediate isn't used in the place of setTimeout ?

Related:

Thank you for reading and for the good job!

@sinclairzx81
Copy link
Owner

Hi, thanks :D

Will close this one as the setImmediate() call went in with optimizations enabling 24-bit true-color support. See PR #10 for details.

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

2 participants