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

JavaScript Scheduler should use window.postMessage, when setImmediate not available #1556

Open
alexandru opened this issue May 9, 2022 · 4 comments

Comments

@alexandru
Copy link
Member

The Scheduler implementation for JavaScript tries to use setImmediate, when available (and right now it's only available on Node.js). Otherwise, it does a fallback to setTimeout, but this operation is throttled by browsers on repeated calls to 4ms, which can be terrible for performance.

An alternative, in browsers, is to fallback on window.postMessage.

See this setImmediate polyfill for inspiration: https://github.com/YuzuJS/setImmediate

@alexandru alexandru changed the title JavaScript Scheduler implementation should also try to use window.postMessage JavaScript Scheduler should use window.postMessage, when setImmediate not available May 9, 2022
@armanbilge
Copy link
Contributor

armanbilge commented May 20, 2022

@alexandru why not use the MacrotaskExecutor as done in #1522? It is based on that setImmediate polyfill you linked.

https://github.com/scala-js/scala-js-macrotask-executor

@alexandru
Copy link
Member Author

@armanbilge I haven't checked the implementation. If it is, then it might be a good idea.

Thanks for the suggestion.

@armanbilge
Copy link
Contributor

I can confirm it is, having worked on that project 😁

@armanbilge
Copy link
Contributor

This can be closed as of #1522.

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

No branches or pull requests

2 participants