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

React 为什么使用 messageChannel 而不是 requestIdleCallback 来执行任务 #73

Open
nmsn opened this issue Jun 25, 2023 · 3 comments
Labels

Comments

@nmsn
Copy link
Contributor

nmsn commented Jun 25, 2023

No description provided.

@nmsn nmsn added the React label Jun 25, 2023
@nmsn
Copy link
Contributor Author

nmsn commented Jun 25, 2023

@nmsn
Copy link
Contributor Author

nmsn commented Jun 25, 2023

  1. 兼容性不好
  2. 一秒最多执行 20 次,满足不了 60Hz 的渲染要求

@nmsn
Copy link
Contributor Author

nmsn commented Jun 25, 2023

使用 messageChannel 的原因:

  1. 首先选择宏任务,因为我们需要去及时的让出主线程(微任务并不会让出主线程也是在更新页面前去执行)。
  2. 其次是宏任务中的选择,MessageChannel,setTimeout,requestAnimationFrame,都是宏任务,setTimeout会浪费4ms(这个大伙可以去看看),requestAnimationFrame 的触发时间是不稳定的(可以看看浏览器的更新页面机制)

https://juejin.cn/post/7170095557443551246

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

No branches or pull requests

1 participant