React: Is React busy when idle?

Created on 18 Jun 2018  路  5Comments  路  Source: facebook/react

I'm using React as the UI layer on WebGL Projects.

See for example: https://github.com/dakom/ball-bounce-frp

My concern is that React/ReactDOM might be doing stuff unexpectedly due to the new improvement to take advantage of idle time.

Does React do anything while ReactDOM.render() and setState() are not being called?

Most helpful comment

Only if you schedule low-priority work (the exact mechanism is to be determined).

React won't make random stuff slower by spending idle time just because it can. :-) The idea is that if something doesn't need to be synchronous then it's better to do it in deferred chunks. React won't create more work for itself out of thin air.

It's the same amount of work overall, so if it's not async, then it's sync and blocks the thread.

All 5 comments

React doesn't do anything in idle time by default in the version 16.

In the future, reconciliation for some state updates might be deferred to idle time instead of being processed synchronously. There will likely be an API to opt into or out of this, but the specifics aren鈥檛 decided on.

React doesn't do anything in idle time by default in the version 16.

I think this is not accurate, IIRC, before we use requestIdleCallback(if we can), and then refactor it to the our own implementation of rIC?

We used it (and now use our own polyfill) in async mode, which is turned off by default in React 16.

With that in mind would it be accurate to say that in async mode, React will do some additional work while idle? (albeit negligible for most scenarios, for a UI layer in gamedev this might be important)

Only if you schedule low-priority work (the exact mechanism is to be determined).

React won't make random stuff slower by spending idle time just because it can. :-) The idea is that if something doesn't need to be synchronous then it's better to do it in deferred chunks. React won't create more work for itself out of thin air.

It's the same amount of work overall, so if it's not async, then it's sync and blocks the thread.

Was this page helpful?
0 / 5 - 0 ratings