tguerin / newton

An Easy To Use Particle Emitter
https://newton.7omtech.fr
MIT License
22 stars 7 forks source link

Newton causes all child widgets to rebuild each frame #22

Closed orkun1675 closed 4 weeks ago

orkun1675 commented 7 months ago

I'm using Bloc + Newton. Before wrapping my widgets with Newton my app would idle without drawin any frames. Now, Flutter is trying to push out 60 FPS even on a static page when no animation is running.

Observe Flutter Performance tool for FPS change.

I've downloaded Android Studio to use the widget rebuild tracker to verify this.

I'll try to put together a minimal app to demonstrate this. In the meantime attaching a screenshot below.

Screenshot 2023-12-08 at 3 18 42 AM
tguerin commented 7 months ago

Right there is a ticker that triggers a setState({}) and it's triggered even if there is no animation causing the extra rebuild.

orkun1675 commented 7 months ago

Is this something that is easy to fix? Happy to take a look if you want.

tguerin commented 4 weeks ago

The fix was made to only rebuild if there is any effect active. Newton requires a rebuild if any effect is active. To avoid having your child rebuild every frame, either declare it as const (if feasible) or move it to a stack, for example, so that only Newton performs the rebuild.