React Native inline styles and performance

前端 未结 2 1931
日久生厌
日久生厌 2020-12-31 01:49

Does the following:


Have any performance implications compared to:

&         


        
2条回答
  •  粉色の甜心
    2020-12-31 02:25

    As mentioned in the comments of the selected answer, the performance comment has been removed from the RN docs, but in my project (a mobile game using RN that uses multiple active Animated components), using Stylesheet instead of inline styles helps performance.

    My main view where around 5~10 Animated components are active, the UI FPS drops to 15~18 when I use inline styles, but if I use Stylesheet it has a 60fps with little to no stagger. Note that I had to implement this in most components especially the Animated components and its child components in order to see the improvements, I still have some inline styles lying around in other components.

    When it comes to performance, your UI FPS is affected by your js activity. So reducing/optimizing JS load will help to keep your FPS perform better. In my project, some style values are computed, but they only need to be computed during the initial load. When I use inline styles, these values are computed every re-render, so using stylesheets makes more sense since there will be no recomputing. This is especially important when handling image assets.

    Bottom line, use Stylesheet when you can. It will help in the long run and avoid any unnecessary updates from inline to stylesheet.

提交回复
热议问题