Render Performance Optimization
Rendering performance affects page smoothness and responsiveness. The more complex the page structure and the more frequent the updates, the greater the rendering pressure.
Reduce Page Node Count
Too many nodes on a page increases memory usage and layout computation time. Keep node count below 1000 per page and tree depth below 30 levels.
Common strategies:
- Remove redundant nesting: Eliminate unnecessary
Viewwrapper layers and keep the structure flat - Conditional rendering: Use
{condition && ...}to remove nodes that aren't needed rather thandisplay: none; for elements that toggle frequently, use thehiddenprop instead to avoid repeatedly creating and destroying nodes
Use Scroll Event Listeners Carefully
onPageScroll and ScrollView's onScroll events fire at a very high frequency. Each trigger has cross-thread communication overhead.
Notes:
- Avoid listening to scroll events when not necessary
- Don't pass an empty
onPageScrollhandler when you don't need it - Avoid calling
setStateor synchronous APIs frequently inside scroll callbacks
Choose High-Performance Animation Approaches
Animations enhance interaction experience. Choosing the right animation approach ensures good visual effects without performance issues.
- Prefer
transformandopacityfor animations — they can leverage GPU acceleration - Avoid animating
width,height,margin,padding, etc. — these trigger layout reflow
Avoid using setState to update state every frame to drive animations. At 60fps, each frame is only ~16ms; cross-thread communication overhead causes severe frame drops. Use RJS for high-frequency interactive animations (such as drag-follow) to respond to events and modify styles directly in the view layer.
Component-Based Decomposition
Split pages into independent child components. State updates within a component only trigger that component's re-render, not the entire page: