pixijs / pixi-react

Write PIXI apps using React declarative style
https://pixijs.io/pixi-react/
MIT License
2.33k stars 177 forks source link

Render only when state changes #315

Closed Specy closed 2 years ago

Specy commented 2 years ago

I have a question, is it possible to cause a render only when state changes? (not faster than the request animation frame) Or whenever I want to cause a render? In my webapp I change state every 80/100 ms, sometimes it doesn't change anything for many seconds too, and I find it a resource waste to re render a static content Everytime.

inlet commented 2 years ago

Hi @Specy, see https://reactpixi.org/stage

Specy commented 2 years ago

Oh wow i managed to improve performance by X2 by changing 2 lines of code i love it.

Are there any drawbacks on using state changes instead of RAF? since react is what decides when and how to change data that will be rendered, i dont understand why RAF should even be a thing, it will just render without a reason if react doesnt update state. Or am i missing something?

inlet commented 2 years ago

Well, it totally depends..

The reason why raf is enabled by default is that this is the preferred "PIXI" way, it uses the internal PIXI ticker to update the entire stage. React reconciler updates are always slower (however, you probably won't notice it really).

In many cases controlling the render() updates yourself gives you more power, but for 90% of all apps raf should suffice.

Specy commented 2 years ago

I guess it's app specific then, i dont notice any visual changes but a lot of performance improvements, so i guess it fits for me, thanks a lot for the info and the wonderful module! This is what i made with it

inlet commented 2 years ago

Looks great @Specy!